QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356248 | #6519. X Equals Y | Djangle162857# | WA | 6ms | 3872kb | C++20 | 1.6kb | 2024-03-17 17:03:45 | 2024-03-17 17:03:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " == " << x << endl
#define el '\n'
typedef long long ll;
const int mod = 1000000007;
const int inf = 2147483647;
const int N = 200020;
void solve()
{
int A, B, x, y;
cin >> x >> y >> A >> B;
A = min(A, x), B = min(B, y);
if (x == y) {
cout << "YES\n";
cout << "2 2\n";
return;
}
if (x == 1 || y == 1) {
cout << "NO" << el;
return;
}
map<vector<int>, int> mp;
for (int i = 2; i * i <= x && i <= A; i++) {
// x->i
int now = x;
vector<int> s;
while (now >= 1) {
s.push_back(now % i);
now = now / i;
}
mp[s] = i;
}
for (int i = 2; i * i <= y && i <= B; i++) {
// x->i
int now = y;
vector<int> s;
while (now >= 1) {
s.push_back(now % i);
now = now / i;
}
if (mp.find(s) != mp.end()) {
cout << "YES" << el;
cout << mp[s] << " " << i << el;
return;
}
}
int flag = 0;
if (x < y) {
swap(x, y);
swap(A, B);
flag = 1;
}
int a, b;
int minb = sqrt(y) + 1;
int mina = sqrt(x) + 1;
for (int p = 1; p * p < x && p * p < y; p++) {
if ((x - y) % p != 0)
continue;
int res = (x - y) / p;
a = min(A, x / p);
b = a - res;
if (a < mina || b < minb)
continue;
int q = x - a * p;
if (q < a && q < b) {
cout << "YES" << el;
if (flag)
swap(a, b);
cout << a << " " << b << el;
return;
}
}
cout << "NO" << el;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
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: -100
Wrong Answer
time: 6ms
memory: 3872kb
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 756 497 YES 17 151 YES 326 25 YES 656 660 YES 80 321 YES 86 75 YES 25 10 YES 175 20 YES 345 417 NO NO YES 134 55 YES 403 486 YES 472 202 YES 107 84 YES 15 188 NO NO YES 443 347 YES 12 249 NO NO YES 16 5 YES 151 120 NO YES 948 544 NO YES 67 196 NO YES 66 29 NO NO YES 728 408 YES 6 5 NO NO NO YES ...
result:
wrong answer Integer parameter [name=b] equals to 25, violates the range [2, 6] (test case 3)