QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#703830 | #6519. X Equals Y | TheZone | AC ✓ | 383ms | 6408kb | C++20 | 4.2kb | 2024-11-02 18:38:00 | 2024-11-02 18:38:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int base = 1000000007;
signed main()
{
int T;
scanf("%d", &T);
int DEBUG = 0;
for (int test = 1; test <= T; ++test) {
int x, y, A, B;
scanf("%d%d%d%d", &x, &y, &A, &B);
if (test >= 200 && DEBUG) {
cout << x << " " << y << " " << A << " " << B << endl;
}
if (x == y) {
if (!DEBUG) {
puts("YES");
puts("2 2");
}
} else if (x == 1 || y == 1) {
if (!DEBUG) {
puts("NO");
}
} else {
unordered_map<unsigned long long, int> M;
for (int i = 2; i * i <= x && i <= A; ++i) {
unsigned long long z = 3, tz = x;
while (tz) {
z = z * base + tz % i + 17;
tz /= i;
}
M[z] = i;
}
int flg = 0;
for (int i = 2; i * i <= y && i <= B; ++i) {
unsigned long long z = 3, tz = y;
while (tz) {
z = z * base + tz % i + 17;
tz /= i;
}
if (M.count(z)) {
if (!DEBUG) {
puts("YES");
printf("%d %d\n", M[z], i);
flg = 1;
}
break;
}
}
if (!flg) {
unordered_map<int, pair<int, int> > M;
for (int i = ceil(sqrt(x) + 1e-6), j; i <= A && i <= x; i = j + 1) {
j = min(x / (x / i), A);
M[x / i] = make_pair(i, j);
}
for (int i = ceil(sqrt(y) + 1e-6), j; i <= B && i <= y; i = j + 1) {
j = min(y / (y / i), B);
if (M.count(y / i) && !((y - x) % (y / i))) {
int l1 = M[y / i].first, r1 = M[y / i].second;
int l2 = i, r2 = j, V = (y - x) / (y / i);
if (l2 - r1 <= V && r2 - l1 >= V) {
if (!DEBUG) {
puts("YES");
int dl = V - (l2 - r1);
if (dl <= r2 - l2) {
printf("%d %d\n", r1, l2 + dl);
} else {
printf("%d %d\n", r1 - (dl - (r2 - l2)), r2);
}
}
flg = 1;
break;
}
}
}
if (!flg) {
if (!DEBUG) {
puts("NO");
}
}
}
}
}
return 0;
}
/*#include <bits/stdc++.h>
using namespace std;
const int base = 1000000007;
signed main()
{
int T;
scanf("%d", &T);
int DEBUG = 0;
for (int test = 1; test <= T; ++test) {
int x, y, A, B;
scanf("%d%d%d%d", &x, &y, &A, &B);
if (test >= 200 && DEBUG) {
cout << x << " " << y << " " << A << " " << B << endl;
}
if (x == y) {
if (!DEBUG) {
puts("YES");
puts("2 2");
}
} else if (x == 1 || y == 1) {
if (!DEBUG) {
puts("NO");
}
} else {
unordered_map<unsigned long long, int> M;
for (int i = 2; i * i <= x && i <= A; ++i) {
unsigned long long z = 3, tz = x;
while (tz) {
z = z * base + tz % i + 17;
tz /= i;
}
M[z] = i;
}
int flg = 0;
for (int i = 2; i * i <= y && i <= B; ++i) {
unsigned long long z = 3, tz = y;
while (tz) {
puts("NO");
}
}
}
}
}
return 0;
}*/
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3920kb
input:
6 1 1 1000 1000 1 2 1000 1000 3 11 1000 1000 157 291 5 6 157 291 3 6 10126 114514 789 12345
output:
YES 2 2 NO YES 3 11 YES 4 5 NO YES 6 10
result:
ok correct (6 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
1000 920 661 756 534 52 454 31 218 980 77 812 6 729 733 289 660 161 643 21 475 602 525 329 274 782 167 279 113 875 100 388 16 426 498 341 417 433 751 312 39 91 50 47 39 941 388 247 46 725 808 148 486 945 405 700 145 647 509 152 445 45 564 16 468 843 40 530 3 722 36 323 22 568 472 443 41 38 749 25 42...
output:
YES 131 94 YES 8 75 NO YES 182 183 NO YES 54 47 YES 25 10 NO YES 23 27 NO NO NO NO YES 52 22 YES 107 84 YES 15 188 NO NO YES 35 29 YES 12 249 NO NO YES 16 5 YES 151 120 NO YES 249 148 NO YES 22 65 NO YES 66 29 NO NO YES 37 21 YES 6 5 NO NO NO NO NO YES 43 17 NO YES 38 36 YES 17 25 YES 96 15 NO NO NO...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 94ms
memory: 4004kb
input:
1000 312788 308299 292039 230765 263760 329714 198045 86472 945524 951268 792172 748100 922790 262573 363596 34883 755556 714487 234743 610394 413603 489527 114329 351936 409240 356171 378350 234973 300813 97383 263307 49846 579258 900270 84403 704902 563965 876076 387516 770189 36896 156893 23161 1...
output:
YES 4668 4601 YES 2691 3364 YES 1316 1324 NO YES 107936 102069 YES 467 521 YES 288042 234973 YES 10027 3246 YES 801 1245 YES 62662 97341 YES 139 338 YES 27151 26694 YES 483 960 YES 1106 587 YES 713 699 YES 1381 9024 NO YES 10657 4166 YES 12558 8399 YES 581 2360 YES 1145 1102 YES 1768 1715 YES 68 138...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 258ms
memory: 6132kb
input:
1000 981241785 906230829 601363803 626653490 197057696 698550046 128696358 449956015 182548925 796382933 101642956 339324198 816288818 177783961 308532802 32376477 628394197 777548138 355072973 757299936 599075146 752655475 473746059 323396924 261214299 95047810 181049121 60329182 7484303 329571035 ...
output:
YES 35005 32329 YES 15698 55648 YES 54720 238723 YES 146893 31992 YES 15326687 18964588 YES 26084 32771 NO YES 4910 216253 YES 1796495 1768498 YES 2335 2446 NO YES 8181622 7836311 YES 52569 390568 YES 43467 45196 YES 66325 101378 YES 3087161 541984 YES 3156893 762966 NO YES 52726 115823 YES 696995 8...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 18ms
memory: 3964kb
input:
1000 11131470 5473008 893 586 160457243 377399003 195 363 33293118 10204988 348 650 76153236 165484206 788 591 363322142 108960566 994 862 10849 1346589 861 662 425071 7754389 221 245 5472186 246060285 479 804 699145 16995055 56 861 215170 3080970 423 722 355522 9691597 211 923 24159424 15965332 579...
output:
YES 36 30 YES 50 62 YES 50 37 NO NO YES 16 86 YES 28 74 YES 10 19 NO YES 33 83 YES 16 37 YES 93 81 YES 70 80 NO YES 50 56 YES 99 29 YES 47 33 YES 2 2 YES 14 77 YES 89 84 YES 42 7 YES 48 93 YES 48 22 YES 63 48 YES 73 96 NO YES 21 20 YES 36 55 YES 68 24 YES 11 89 YES 36 64 YES 13 34 YES 57 59 YES 65 6...
result:
ok correct (1000 test cases)
Test #6:
score: 0
Accepted
time: 383ms
memory: 6408kb
input:
1000 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 994905890 324112256 607121052 999502221 99490...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
ok correct (1000 test cases)