QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359053#6519. X Equals YPorNPtreeWA 8ms4072kbC++142.9kb2024-03-20 11:33:482024-03-20 11:33:48

Judging History

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

  • [2024-03-20 11:33:48]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:4072kb
  • [2024-03-20 11:33:48]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int B = 1000000007;

signed main()
{
    int T;
    scanf("%d", &T);
    int DEBUG = (T == 1000);
    for (int test = 1; test <= T; ++test) {
        int x, y, A, B;
        scanf("%d%d%d%d", &x, &y, &A, &B);
        if (test >= 200) {
            cerr << 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 * B + 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 * B + 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;
}

详细

Test #1:

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

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: 8ms
memory: 3632kb

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:


result:

wrong output format Unexpected end of file - token expected (test case 1)