QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555848#5103. Fair DivisionRico64WA 3ms7648kbC++232.9kb2024-09-10 11:02:112024-09-10 11:02:11

Judging History

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

  • [2024-09-10 11:02:11]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:7648kb
  • [2024-09-10 11:02:11]
  • 提交

answer

#include <iostream>

using namespace std;

__int128 powr(__int128 a, __int128 b, __int128 num) {
    if (a == 1) return 1;
    if (b > 75) return -1;
    __int128 r = 1;
    int i;
    for (i = 0; i < b && r <= (num + a - (__int128)1L) / a; r *= a, ++i);
    if (i >= b && r <= num) {
        return r;
    } else {
        return -1;
    }
}

int main() {
    long long ni, mi;
    cin >> ni >> mi;
    __int128 n = ni;
    __int128 m = mi;
    if (n > 160) {
        cout << "impossible" << endl;
        return 0;
    }
    __int128 cache[20206][ni];
    fill(cache[0], cache[0] + n, (__int128)0);
    fill(cache[1], cache[1] + n, (__int128)1);
    cout << "h" << endl;
    for (__int128 q = 2; q < 20206; ++q) {
        cache[q][0] = (__int128)1;
        cache[q][1] = (__int128)q;
        __int128 num = m * (__int128)20206;
        for (__int128 i = 2; i < n; ++i) {
            if (cache[q][i - 1] == -1 || cache[q][i - 1] > (num + q - 1) / q) {
                cache[q][i] = -1;
            } else {
                cache[q][i] = cache[q][i - 1] * q;
                if (cache[q][i] > num) cache[q][i] = -1;
            }
        }
    }
    cout << "midpoint" << endl;
    for (__int128 q = 2; q < 20206; ++q) {
        for (__int128 p = q - 1; p > 0; --p) {
            __int128 num = (__int128)m * (__int128)(q - p);
            __int128 tsum = 0;
            bool flag = true;
            for (__int128 i = 0; i < n; ++i) {
                __int128 le = cache[p][i];
                __int128 ri = cache[q][n - 1 - i];
                if (le == -1 || ri == -1 || le > (num - tsum + ri - 1) / ri) {
                    flag = false;
                    break;
                }
                tsum += le * ri;
            }
            if (!flag || num < tsum) {
                break;
            }
            __int128 rem = num % tsum;
            if (rem != 0) continue;
            cout << (long long)(q - p) << ' ' << (long long)q << endl;
            return 0;
        }
        for (__int128 p = 1; p < q; ++p) {
            __int128 num = (__int128)m * (__int128)(q - p);
            __int128 tsum = 0;
            bool flag = true;
            for (__int128 i = 0; i < n; ++i) {
                __int128 le = powr(p, i, num - tsum);
                __int128 ri = powr(q, n - 1 - i, num - tsum);
                if (le == -1 || ri == -1 || le > (num - tsum + ri - 1) / ri) {
                    flag = false;
                    break;
                }
                tsum += le * ri;
            }
            if (!flag || num < tsum) {
                break;
            }
            __int128 rem = num % tsum;
            if (rem != 0) continue;
            cout << (long long)(q - p) << ' ' << (long long)q << endl;
            return 0;
        }
    }
    cout << "impossible" << endl;

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 7648kb

input:

13 382475111752106101

output:

h
midpoint
17 28

result:

wrong answer 1st lines differ - expected: '17 28', found: 'h'