結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 11 ms
4,352 KB
testcase_02 AC 258 ms
4,348 KB
testcase_03 AC 257 ms
4,348 KB
testcase_04 AC 163 ms
4,352 KB
testcase_05 AC 164 ms
4,352 KB
testcase_06 AC 163 ms
4,352 KB
testcase_07 AC 172 ms
4,348 KB
testcase_08 AC 182 ms
4,352 KB
testcase_09 AC 199 ms
4,352 KB
testcase_10 AC 241 ms
4,352 KB
testcase_11 AC 279 ms
4,348 KB
testcase_12 AC 315 ms
4,352 KB
testcase_13 AC 357 ms
4,352 KB
testcase_14 AC 540 ms
4,348 KB
testcase_15 AC 307 ms
4,432 KB
testcase_16 AC 238 ms
4,348 KB
testcase_17 AC 187 ms
4,348 KB
testcase_18 AC 182 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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 << 0 << 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