CSES - NOI 2024 - Results
Submission details
Task:Chair Game
Sender:Veikko Heikkinen
Submission time:2024-03-06 18:29:46 +0200
Language:C++20
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:47:39: error: 'a' was not declared in this scope
   47 |         } while (next_permutation(all(a)));
      |                                       ^
input/code.cpp:4:22: note: in definition of macro 'all'
    4 | #define all(x) begin(x),end(x)
      |                      ^

Code

#include <bits/stdc++.h>

#define debug(x) cout << #x << ": " << x << endl
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define fi first
#define se second

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void solve() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    vector<bool> has(n+1, 0);
    
    int s = 0;
    bool uniq = 1;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        s += v[i];
        uniq &= !has[v[i]];
        has[v[i]] = 1;
    }
    
    if (s % n != 0) {
        cout << "NO\n";
        return;
    }
    
    cout << "YES\n";
    if (n <= 8) {
        sort(all(v));
        vector<int> p(n);
        iota(all(p), 0);
        do {
            vector<int> q(n);
            for (int i = 0; i < n; ++i) q[i] = (i + v[i]) % n;
            sort(all(q));
            if (p == q) {
                for (int i = 0; i < n; ++i) cout << v[i] << " \n"[i == n-1];
                return;
            }
        } while (next_permutation(all(a)));
    } else if (uniq) {
        for (int i = 1; i <= n; ++i) cout << i << " \n"[i == n];
    } else {
        
    }
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    int t;
    cin >> t;
    while (t--) solve();
    
    return 0;
}