QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#234245#6519. X Equals Yucup-team1198#AC ✓1010ms9240kbC++202.4kb2023-11-01 15:10:062023-11-01 15:10:07

Judging History

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

  • [2023-11-01 15:10:07]
  • 评测
  • 测评结果:AC
  • 用时:1010ms
  • 内存:9240kb
  • [2023-11-01 15:10:06]
  • 提交

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()

#define int int64_t

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;
        int k = 0;
        if (a > A) {
            k = max(k, a - A);
        }
        if (b > B) {
            k = max(k, b - B);
        }
        a -= k;
        b -= k;
        q += k * 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;
        k = 0;
        if (a > A) {
            k = max(k, a - A);
        }
        if (b > B) {
            k = max(k, b - B);
        }
        a -= k;
        b -= k;
        q += k * 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;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3420kb

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
789 9488

result:

ok correct (6 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3448kb

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
NO
YES
182 183
NO
YES
86 75
YES
260 55
NO
YES
341 413
NO
NO
NO
NO
YES
415 145
YES
107 84
YES
15 188
NO
NO
YES
35 29
YES
12 249
NO
NO
YES
196 20
YES
151 120
NO
YES
750 346
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
237 224
YES
211 411
Y...

result:

ok correct (1000 test cases)

Test #3:

score: 0
Accepted
time: 41ms
memory: 3632kb

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
235254 230765
YES
37680 47102
YES
742356 748100
NO
YES
107936 102069
YES
114329 139637
YES
288042 234973
YES
253276 49846
YES
84403 137905
YES
387516 699627
YES
23161 143158
YES
40881 39967
YES
16611 32988
YES
344148 131877
YES
109082 105544
YES
1381 9024
NO
YES
536175 185661
YES
138141 92392
YE...

result:

ok correct (1000 test cases)

Test #4:

score: 0
Accepted
time: 144ms
memory: 8440kb

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
601363803 526352847
YES
98528848 349275023
YES
60849641 265460977
YES
146893 31992
YES
355072973 504226914
YES
199691715 250885158
NO
YES
1989475 109351719
YES
1796495 1768498
YES
285937908 314086990
NO
YES
8181622 7836311
YES
23288110 182823638
YES
5831779 6063750
YES
83494380 131061301
YES
117...

result:

ok correct (1000 test cases)

Test #5:

score: 0
Accepted
time: 62ms
memory: 3652kb

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: 1010ms
memory: 9240kb

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)