QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#513904#9176. Non-Interactive Nimucup-team3734#TL 0ms0kbC++231.1kb2024-08-10 20:40:292024-08-10 20:40:29

Judging History

你现在查看的是最新测评结果

  • [2024-08-10 20:40:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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

output:


result: