QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#752434 | #858. GCD vs. XOR | kangkunma | WA | 18349ms | 143264kb | C++20 | 1.3kb | 2024-11-16 02:57:54 | 2024-11-16 02:57:55 |
Judging History
answer
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
using namespace std;
const int MAX = 1000001;
vector<vector<int>> D(MAX);
void initialize() {
for (int i = 0; i < 1000; ++i) {
for (int j = i + 1; j < MAX / (i + 1); ++j) {
if (((i + 2) * j == j | (i + 1) * j)) {
D[(i + 1) * j].push_back(i + 1);
}
}
}
}
long long s(const vector<int>& l) {
vector<int> C(MAX, 0);
long long A = 0;
for (int i : l) {
C[i]++;
}
set<int> unique_l(l.begin(), l.end());
for (int i : unique_l) {
for (int j : D[i]) {
if (i + j > MAX) break;
if ((i + j) == (j | i)) {
A += static_cast<long long>(C[i]) * C[j + i];
}
if (i / j + i <= MAX) {
if ((i + i / j) == (i / j | i) && j * j != i) {
A += static_cast<long long>(C[i]) * C[i / j + i];
}
}
}
}
return A;
}
int main() {
initialize();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> l(n);
for (int i = 0; i < n; ++i) {
cin >> l[i];
}
cout << s(l) << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 266ms
memory: 91352kb
input:
1 4 2 3 4 3
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 258ms
memory: 91504kb
input:
20 43 128 66 452 384 400 441 232 203 228 33 284 156 128 190 197 292 388 31 179 343 147 206 450 284 180 73 273 130 168 250 405 203 235 340 309 28 267 395 152 191 295 463 344 54 48 7 12 37 49 24 5 18 15 37 26 57 53 59 22 10 2 16 36 52 64 1 56 42 38 46 53 7 2 8 60 38 54 11 19 50 20 61 6 50 27 5 26 3 4 ...
output:
9 54 13 7 8 34 47 11 1 102 6 5 37 1 3 8 8 348 15 0
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 18349ms
memory: 143264kb
input:
20 1318434 383714 853663 66866 511925 858736 184314 296349 849141 468962 414270 917939 220934 778184 984811 194692 105206 528188 310859 57152 790101 274637 529663 931099 79533 179471 539390 210762 400829 514992 127623 369248 168711 380204 767781 753089 645551 714964 101060 340524 937457 928656 65201...
output:
3032046 3661009 2800799 2440602 4854508 3744477 2051988 2014444 1784404 4514141 3348718 2477338 2051404 2133141 3042193 4827212 4227070 2349812 6977138 999999972775
result:
wrong answer 2nd numbers differ - expected: '3638995', found: '3661009'