結果

問題 No.97 最大の値を求めるくえり
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-14 11:05:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,478 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 167,876 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-13 03:48:02
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 261 ms
4,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long mod = 100003;

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
    unsigned t = xor128_x ^ (xor128_x << 11);
    xor128_x = xor128_y;
    xor128_y = xor128_z;
    xor128_z = xor128_w;
    return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8));
}
void generateA(int N, int A[]) {
    for (int i = 0; i < N; ++i)
        A[i] = xor128() % 100003;
}

int main() {
    int N, Q, A[100010] = {};
    cin >> N >> Q;
    generateA(N, A);

    sort(A, A + N);
    int cnt[100010] = {};
    for (int i = 0; i < N; i++) {
        cnt[A[i]] = 1;
    }

    auto modpow = [&](long long a, int n) {
        long long t = 1;
        while (n) {
            if (n & 1)
                (t *= a) %= mod;
            (a *= a) %= mod;
            n >>= 1;
        }
        return t;
    };


    while (Q--) {
        long long q;
        cin >> q;
        if (q == 0) {
            cout << A[N - 1] << endl;
            continue;
        }
        long long ans = 0;
        if (N < 3333) {
            for (int i = 0; i < N; i++) {
                ans = max(ans, (A[i] * q) % mod);
            }
        } else {
            for (int i = mod - 1; i >= 0; i--) {
                if (cnt[(modpow(q, mod - 2) * i) % mod]) {
                    ans = i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}
0