QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#522797#9176. Non-Interactive Nimhhu_yjhWA 0ms3584kbC++171.6kb2024-08-17 14:37:432024-08-17 14:37:44

Judging History

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

  • [2024-08-17 14:37:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3584kb
  • [2024-08-17 14:37:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
typedef long long ll;
typedef pair<ll, ll> PII;
ll n, k;
ll a[N];

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<set<int>> cnt(63);  // 63位,0到62
    for (int i = 1; i <= n; i++) {
        for (int j = 62; j >= 0; j--) {
            if (a[i] >> j & 1) {
                cnt[j].insert(i);
                break;  // 只插入最高有效位
            }
        }
    }
    
    vector<pair<ll, ll>> ans;
    
    auto work = [&](ll x, ll y) {
        ll temp = 0;
        for (int k = 62; k >= 0; k--) {
            if ((a[x] >> k & 1) && (a[y] >> k & 1)) {
                cnt[k].erase(x);
                cnt[k].erase(y);
                a[x] -= 1ll << k;
                a[y] -= 1ll << k;
                temp += 1ll << k;
                if (a[x] > 0) cnt[k].insert(x);
                if (a[y] > 0) cnt[k].insert(y);
            }
        }
        ans.push_back({x, temp});
    };
    
    for (int i = 62; i >= 0; i--) {
        if (cnt[i].size() == 0) continue;
        if (cnt[i].size() != 2) {
            cout << -1 << endl;
            return;
        }
        ll x = *cnt[i].begin();
        cnt[i].erase(x);
        ll y = *cnt[i].begin();
        cnt[i].clear();
        work(x, y);
    }
    
    cout << ans.size() << endl;
    for (auto j : ans) {
        cout << j.first << ' ' << j.second << endl;
    }
}

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

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

input:

2
4
4 2 7 1
4
1 1 1 1

output:

-1
-1

result:

wrong answer judge has answer but participant doesn't (test case 1)