QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515463#8517. Interesting Pathsk1nsomWA 0ms3820kbC++171.4kb2024-08-11 17:56:312024-08-11 17:56:32

Judging History

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

  • [2024-08-11 17:56:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-08-11 17:56:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define PII pair<int, int>
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N];
void solve()
{
    cin >> n;
    vector<vector<int>> pre(65);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        for (int j = 60; j >= 0; j--)
            if (a[i] & (1ll << j))
                pre[j].push_back(i);
    }
    for (int i = 0; i <= 60; i++)
        sort(pre[i].begin(), pre[i].end());
    vector<PII> ans;
    for (int j = 60; j >= 0; j--)
    {
        if (pre[j].size() > 2)
        {
            cout << -1 << endl;
            return;
        }
        else if (pre[j].size() == 2)
        {
            int x = pre[j][0], y = pre[j][1];
            int tmp = a[x] & a[y];
            for (int i = j - 1; i >= 0; i--)
                if (tmp & (1ll << i))
                {
                    pre[i].erase(lower_bound(pre[i].begin(), pre[i].end(), x));
                    pre[i].erase(lower_bound(pre[i].begin(), pre[i].end(), y));
                }
            ans.push_back({pre[j][0], tmp});
        }
    }
    cout << ans.size() << endl;
    for (auto [x, y] : ans)
        cout << x << ' ' << y << endl;
}
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 7
1 3
3 5
1 2
2 3
3 4
4 5
2 4

output:

-1
1
2 4
-1
-1
-1

result:

wrong answer 1st numbers differ - expected: '4', found: '-1'