QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#513904 | #9176. Non-Interactive Nim | ucup-team3734# | TL | 0ms | 0kb | C++23 | 1.1kb | 2024-08-10 20:40:29 | 2024-08-10 20:40:29 |
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(), (x).end()
ll bit(ll mask, ll k) {
return (mask >> k) & 1;
}
ll big(ll mask) {
for (ll k = 70; k >= 0; --k)
if (bit(mask, k))
return k;
}
void solve() {
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector<pair<ll, ll>> ans;
while (true) {
ll at = max_element(all(a)) - a.begin();
ll mx = a[at];
ll k = big(mx);
if (k == 0)
break;
ll cnt = 0;
for (ll x : a)
if (big(x) == k)
++cnt;
if (cnt > 2) {
cout << "-1\n";
return;
}
ans.emplace_back(at, mx);
a[at] = 0;
ll s = max_element(all(a)) - a.begin();
ll rest = 0;
for (int i = 0; i < n; ++i)
if (i != s)
rest ^= a[i];
a[s] = rest; // second moves
}
cout << ans.size() << "\n";
for (auto [at, what] : ans)
cout << at + 1 << " " << what << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4 4 2 7 1 4 1 1 1 1