QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234235#6519. X Equals Yucup-team1198#WA 3ms3908kbC++202.0kb2023-11-01 15:01:552023-11-01 15:01:55

Judging History

你现在查看的是最新测评结果

  • [2023-11-01 15:01:55]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3908kb
  • [2023-11-01 15:01:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

void print(int a, int b, bool is_swap) {
    if (is_swap) swap(a, b);
    cout << a << " " << b << "\n";
}

vector<int> get(int x, int b) {
    vector<int> ans;
    while (x) {
        ans.push_back(x % b);
        x /= b;
    }
    return ans;
}

void solve() {
    int x, y, A, B;
    cin >> x >> y >> A >> B;
    if (x == y) {
        cout << "YES\n2 2\n";
        return;
    }
    bool is_swap = false;
    if (x > y) {
        swap(x, y);
        swap(A, B);
        is_swap = true;
    }
    for (int p = 1; p * p <= y - x; ++p) {
        if ((y - x) % p != 0) continue;
        int q = x % p;
        int a = x / p;
        int b = y / p;
        if (p < a && q < a && a <= A && b <= B && a >= 2) {
            cout << "YES\n";
            print(a, b, is_swap);
            return;
        }
        p = (y - x) / p;
        q = x % p;
        a = x / p;
        b = y / p;
        if (p < a && q < a && a <= A && b <= B && a >= 2) {
            cout << "YES\n";
            print(a, b, is_swap);
            return;
        } 
        p = (y - x) / p;
    }
    vector<pair<vector<int>, int>> varx;
    for (int a = 2; a * a <= x && a <= A; ++a) {
        varx.emplace_back(get(x, a), a);
    }
    vector<pair<vector<int>, int>> vary;
    for (int b = 2; b * b <= y && b <= B; ++b) {
        vary.emplace_back(get(y, b), b);
    }
    sort(varx.begin(), varx.end());
    sort(vary.begin(), vary.end());
    int id = 0;
    for (auto elem : varx) {
        while (id + 1 < (int)vary.size() && vary[id].first < elem.first) ++id;
        if (vary[id].first == elem.first) {
            int a = elem.second, b = vary[id].second;
            cout << "YES\n";
            print(a, b, is_swap);
            return;
        }
    }
    cout << "NO\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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: 3ms
memory: 3908kb

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
17 151
NO
YES
182 183
NO
YES
86 75
YES
260 55
NO
YES
213 249
NO
NO
NO
NO
YES
315 135
YES
107 84
YES
15 188
NO
NO
YES
35 29
YES
12 249
NO
NO
YES
196 20
YES
151 120
NO
YES
498 296
NO
YES
67 196
NO
YES
66 29
NO
NO
YES
94 54
YES
6 5
NO
NO
NO
NO
NO
YES
324 129
NO
YES
38 36
YES
109 209
YES
...

result:

wrong answer you didn't find a solution but jury did (test case 54)