QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#139580 | #6519. X Equals Y | ethening | AC ✓ | 1799ms | 8968kb | C++17 | 2.2kb | 2023-08-13 23:06:06 | 2023-08-13 23:06:09 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve() {
int x, y, A, B;
cin >> x >> y >> A >> B;
if (x == y) {
cout << "YES\n2 2\n";
return;
}
int ali = 2;
int bli = 2;
map<vector<int>, int> M;
for (int i = 2; i <= A && i * i <= x; i++) {
vector<int> v;
int j = x;
while (j > 0) {
v.push_back(j % i);
j /= i;
}
M[v] = i;
ali = i + 1;
}
for (int i = 2; i <= B && i * i <= y; i++) {
vector<int> v;
int j = y;
while (j > 0) {
v.push_back(j % i);
j /= i;
}
if (M.count(v)) {
cout << "YES\n";
cout << M[v] << " " << i << "\n";
return;
}
bli = i + 1;
}
// cout << "enddddd" << endl;
map<int, array<int, 4>> M2;
for (int al = ali, ar; al <= min(A, x); al = ar + 1) {
ar = x / (x / al);
ar = min(ar, min(A, x));
int q = x / al;
int reml = x - q * al;
int remr = x - q * ar;
// reml > remr
M2[q] = {al, reml, ar, remr};
// cout << "!!!" << al << " " << ar << ": " << q << endl;
// cout << "rem: " << reml << " " << remr << endl;
}
for (int bl = bli, br; bl <= min(B, y); bl = br + 1) {
br = y / (y / bl);
br = min(br, min(B, y));
int q = y / bl;
int reml = y - q * bl;
int remr = y - q * br;
// cout << "!!!" << bl << " " << br << ": " << q << endl;
// cout << "rem: " << reml << " " << remr << endl;
if (!M2.count(q)) continue;
auto [al, areml, ar, aremr] = M2[q];
if ((areml - reml) % q != 0) continue;
if (remr > areml || aremr > reml) continue;
if (reml >= areml && areml >= remr) {
cout << "YES\n";
cout << (x - areml) / q << " " << (y - areml) / q << "\n";
return;
}
if (reml >= aremr && aremr >= remr) {
cout << "YES\n";
cout << (x - aremr) / q << " " << (y - aremr) / q << "\n";
return;
}
if (areml >= reml && reml >= aremr) {
cout << "YES\n";
cout << (x - reml) / q << " " << (y - reml) / q << "\n";
return;
}
if (areml >= remr && remr >= aremr) {
cout << "YES\n";
cout << (x - remr) / q << " " << (y - remr) / q << "\n";
return;
}
}
cout << "NO\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
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 2 10 YES 4 5 NO YES 6 10
result:
ok correct (6 test cases)
Test #2:
score: 0
Accepted
time: 3ms
memory: 3500kb
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 146 147 NO YES 51 44 YES 25 10 NO YES 23 27 NO NO NO NO YES 52 22 YES 107 84 YES 12 185 NO NO YES 34 28 YES 10 247 NO NO YES 16 5 YES 151 120 NO YES 249 148 NO YES 20 63 NO YES 66 29 NO NO YES 37 21 YES 6 5 NO NO NO NO NO YES 43 17 NO YES 36 34 YES 17 25 YES 96 15 NO NO NO...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 265ms
memory: 3684kb
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 2665 3338 YES 1316 1324 NO YES 107936 102069 YES 467 521 YES 231155 178086 YES 10027 3246 YES 801 1245 YES 56397 91076 YES 139 338 YES 27151 26694 YES 483 960 YES 1106 587 YES 713 699 YES 1360 9003 NO YES 10657 4166 YES 12558 8399 YES 580 2359 YES 1144 1101 YES 1765 1712 YES 68 138...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 999ms
memory: 8896kb
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 15697 55647 YES 54705 238708 YES 146893 31992 YES 14961767 18599668 YES 26084 32771 NO YES 4908 216251 YES 1796495 1768498 YES 2335 2446 NO YES 8181622 7836311 YES 52542 390541 YES 43464 45193 YES 66310 101363 YES 3087161 541984 YES 3156893 762966 NO YES 52717 115814 YES 696995 8...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 52ms
memory: 3640kb
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: 1799ms
memory: 8968kb
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)