CSES - NOI 2024 - Results
Submission details
Task:Chair Game
Sender:Theodor Beskow
Submission time:2024-03-06 19:58:56 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:59:13: error: expected ';' before 'while'
   59 |     srand(3)
      |             ^
      |             ;
   60 |     while(t--){
      |     ~~~~~    
input/code.cpp:57:8: warning: unused variable 'ver' [-Wunused-variable]
   57 |     ll ver = 0;
      |        ^~~
input/code.cpp:58:8: warning: unused variable 'startTime' [-Wunused-variable]
   58 |     ll startTime = chrono::steady_clock::now().time_since_epoch().count();
      |        ^~~~~~~~~

Code

#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define INF ((ll)1e9+7ll)
#define fo(i, n) for(ll i = 0; i<((ll)n); i++)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define deb(x) cout << #x << " = " << (x) << endl
#define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pl;
typedef vector<pl> vpl;
 
vl v;
// vvl memo;
ll n;
 
 
// int dp(int pos, int mask = 0){
//     if(pos == n) return 1;
//     if(memo[pos][mask]) return 0;
//     memo[pos][mask] = 1;
 
// }
ll best;
vl current;
 
bool check(){
    vl res(n, 0);
    fo(i, n){
        if(res[(i+v[i])%n]){
            if(i>best){
                current = v;
                best = i;
            }
            
            return 0;
        }
        res[(i+v[i])%n] = 1;
    }
    return 1;
}
 
int main(){
    cin.tie(0)->sync_with_stdio(0);
    
 
    ll t, tt;
    cin >> t;
    tt = t;
    ll ver = 0;
    ll startTime = chrono::steady_clock::now().time_since_epoch().count();
    srand(3)
    while(t--){
        cin >> n;
        ver++;
        v.assign(n, 0);
        // current.assign(n, 0);
 
        fo(i, n){
            cin >> v[i];
        }
        bool fail = 1;
        best = -1;
        current = v;
        // deb(1);
        // memo.assign(n, vl((1<<n), 0));
        while((chrono::steady_clock::now().time_since_epoch().count()-startTime)/1000 <(900000/tt)*ver){
            // deb((chrono::steady_clock::now().time_since_epoch().count()-startTime)/1000);
            if(check()){
                // deb(t);
                fail = 0;
                break;
            }
            v = current;
            fo(ii, 3) swap(v[best], v[rand()%n]);
        }
        // deb(fail);
        if(fail) cout << "NO\n";
        else{
            cout << "YES\n";
            fo(i, n) cout << v[i] << " ";
            cout << "\n";
        }
        // if(!dp(0, 0)) cout << "NO\n";
    }
 
    return 0;
}