CSES - NOI 2024 - Results
Submission details
Task:Chair Game
Sender:Sofie Fu
Submission time:2024-03-18 18:55:42 +0200
Language:C++20
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool check(long long int, long long int, long long int, long long int)':
input/code.cpp:47:17: error: 'lv' was not declared in this scope; did you mean 'lb'?
   47 |         cout << lv << "\n";
      |                 ^~
      |                 lb
input/code.cpp: In function 'void solve()':
input/code.cpp:79:19: warning: unused variable 'a2' [-Wunused-variable]
   79 |     int a1 = n-2, a2 = n-1, b1 = *notChosenB.begin(), b2 = *notChosenB.rbegin(), u1 = *notChosenC.begin(), u2 = *notChosenC.rbegin();
      |                   ^~

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vo vector
#define pb push_back
#define se second
#define fi first
#define sz(x) x.size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define umap unordered_map
#define uset unordered_set

#define rep(i, a, b) for(ll i=(a); i<b; i++)
#define pr1(x) cerr << #x << '=' << x << ' ';
//for google contests
#define all(v) v.begin(), v.end()
#define repd(i, a, b) for(ll i=(b-1); i >= a; i--)
void _pr(signed x) {cerr << x;}
void _pr(long long x) {cerr << x;}
void _pr(unsigned long long x) {cerr << x;}
void _pr(double x) {cerr << x;}
void _pr(char x) {cerr << '\'' << x << '\'';}
void _pr(const char* x) {cerr << x;}
void _pr(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V> void _pr(const pair<T, V> &x);
template<typename T, typename V> void _pr(const pair<T, V> &x) {cerr << "\e[95m" << "[ "; _pr(x.first); cerr << ", "; _pr(x.second); cerr << "\e[95m" << ']';}
template<typename T> void _pr(const T &x) {int F=0; cerr << '{'; for(auto &i: x) cerr << (F++ ? ", " : ""), _pr(i); cerr << "\e[91m" << '}';}
template <typename T, typename... V> void _pr(T t, V... v) {_pr(t); if(sizeof...(v)) cerr << ", "; _pr(v...);}
#define pr(x...) cerr << "\e[91m" << __func__ << ':' << __LINE__ << " [" << #x << "] = ["; _pr(x); cerr << "\e[91m" << ']' << "\033[0m"  << endl;

//go for outline with ;, then details
ll const inf = LLONG_MAX, mxn = 105;
int t, n;
map<int, pii> abc;

bool check(int a, int b, int u, int lb){
    // pr(a, b, u)
    if((a+b)%n == u){
        abc[a] = {b, u};
        
        cout << "YES\n";
        rep(i, 0, n-1){
            cout << abc[i].fi << " ";
        }
        cout << lv << "\n";

        return 1;
    }
    return 0;
}

void solve(){
    cin>>n; abc.clear();
    vi a(n), b(n); int sum = 0;
    iota(all(a), 0);
    multiset<int> notChosenB, notChosenC;
    rep(i, 0, n) {cin>>b[i]; sum+=b[i]; notChosenB.insert(b[i]); notChosenC.insert(i);}

    if(sum % n) {cout << "NO\n"; return;}

    // pr(notChosenB)
    // pr(notChosenC)
    rep(i, 0, n-2){
        for(auto x: notChosenB){
            int ns = (i+x)%n;
            if(notChosenC.count(ns)){
                abc[i] = {x, ns};

                notChosenC.erase(ns);
                notChosenB.erase(notChosenB.find(x));
                break;
            }
        }
    }
    // pr(notChosenB)
    // pr(notChosenC);
    int a1 = n-2, a2 = n-1, b1 = *notChosenB.begin(), b2 = *notChosenB.rbegin(), u1 = *notChosenC.begin(), u2 = *notChosenC.rbegin();
    while(1){
        if(check(a1, b1, u1, b2)) return;
        if(check(a1, b1, u2, b2)) return;
        if(check(a1, b2, u1, b1)) return;
        if(check(a1, b2, u2, b1)) return;

        //swap
        int ar1 = (u1-b1)%n;
        b1 = b2, u1 = u2;
        b2 = abc[ar1].fi, u2 = abc[ar1].se;
        abc[ar1] = {b1, u1};
        
    }





}

signed main(){
    cin.tie(0)->sync_with_stdio(0);
    cin>>t;
    rep(_, 0, t){
        solve();
    }
}

/*
1
5
4 1 2 1 2
*/