QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308581 | #8132. Freshman's Dream | ucup-team2112# | AC ✓ | 49ms | 3656kb | C++20 | 1.6kb | 2024-01-20 10:45:26 | 2024-01-20 10:45:26 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
int dp[64][2][2];
std::tuple<int, int, int, int> pre[64][2][2];
void solve(){
memset(dp, 0, sizeof(dp));
i64 n;
std::cin >> n;
dp[0][0][0] = 1;
for (int i = 0; i < 60; i += 1) {
int c = n >> i & 1;
for (int j = 0; j < 2; j += 1) {
for (int k = 0; k < 2; k += 1) {
if (!dp[i][j][k]) continue;
for (int p = 0; p < 2; p += 1) {
for (int q = 0; q < 2; q += 1) {
if ((p + q + j) % 2 != (p ^ ((c + q + k) % 2))) {
continue;
}
dp[i + 1][(p + q + j) / 2][(c + q + k) / 2] = dp[i][j][k];
pre[i + 1][(p + q + j) / 2][(c + q + k) / 2] = {p, q, j, k};
}
}
}
}
}
if (!dp[60][0][0]) {
std::cout << -1 << "\n";
return;
}
i64 a = 0, b = 0;
int cur = 60;
int j = 0, k = 0;
while(cur) {
auto [p, q, jj, kk] = pre[cur][j][k];
a |= (i64)p << (cur - 1);
b |= (i64)q << (cur - 1);
j = jj;
k = kk;
cur -= 1;
}
std::cout << a << " " << b << "\n";
// assert((a + b) == (a ^ (b + n)));
// assert((a < (1ll << 60)) && (b < (1ll << 60)));
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T;
std::cin >> T;
while(T--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
5 2 3 6 10 18
output:
576460752303423487 576460752303423487 -1 576460752303423487 576460752303423485 576460752303423487 576460752303423483 576460752303423487 576460752303423479
result:
ok ok
Test #2:
score: 0
Accepted
time: 36ms
memory: 3616kb
input:
100000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
576460752303423487 576460752303423487 -1 576460752303423487 576460752303423486 -1 576460752303423487 576460752303423485 -1 576460752303423487 576460752303423484 -1 576460752303423487 576460752303423483 -1 576460752303423487 576460752303423482 -1 576460752303423487 576460752303423481 -1 5764607523034...
result:
ok ok
Test #3:
score: 0
Accepted
time: 34ms
memory: 3564kb
input:
100000 76316 55087 1035148 480523 322879 607749 440658 434700 941531 657517 247448 953385 569641 592597 188131 769378 397552 94739 487375 142576 407344 532339 798526 521099 294428 414998 415977 646853 941103 21816 299379 1029240 171218 784108 711027 121363 223925 197035 899124 613355 178257 213375 3...
output:
576460752303423487 576460752303385330 -1 576460752303423487 576460752302905914 -1 -1 -1 576460752303423487 576460752303203159 576460752303423487 576460752303206138 -1 -1 576460752303423487 576460752303299764 -1 -1 -1 -1 576460752303423487 576460752303038799 576460752303423487 576460752303224712 -1 -...
result:
ok ok
Test #4:
score: 0
Accepted
time: 39ms
memory: 3612kb
input:
100000 279938093875 699023415517 1048269983590 537007992988 908117019805 683806387338 334400705624 484515916103 888494261285 220468538805 253319179778 357268673752 644637898889 919322454545 854350801341 1022830170092 486578580191 750669735889 4206967959 937169662800 852140555915 924210466276 2534095...
output:
-1 -1 576460752303423487 576460228168431693 576460752303423487 576460483799426994 -1 576460752303423487 576460410400229819 576460752303423487 576460585103070676 -1 -1 -1 576460752303423487 576460625643833599 576460752303423487 576460573669086612 -1 -1 -1 576460752303423487 576460240888338442 -1 -1 -...
result:
ok ok
Test #5:
score: 0
Accepted
time: 49ms
memory: 3532kb
input:
100000 1040995214518856201 963834979320064344 718413469456747239 720594233881658007 133510227004253867 342816554559204856 24244360004792499 32003367585596768 68757795892900724 211638297745299764 478782413658379896 503496146580989968 288072253164348517 131667719615682949 186429177128265488 6043925869...
output:
-1 576460752303423487 94543262643391316 -1 -1 -1 576460752303423487 405052475023821060 -1 576460752303423487 560459068510625104 576460752303423487 542081854356973126 576460752303423487 470641603430773606 576460752303423487 337069545474233540 576460752303423487 324712679012928504 -1 -1 57646075230342...
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
1 1152921504606846975
output:
-1
result:
ok ok
Extra Test:
score: 0
Extra Test Passed