結果

問題 No.97 最大の値を求めるくえり
ユーザー face4face4
提出日時 2019-12-28 16:47:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 458 ms / 5,000 ms
コード長 1,334 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 67,864 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 09:02:50
合計ジャッジ時間 6,002 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 21 ms
6,816 KB
testcase_02 AC 226 ms
6,816 KB
testcase_03 AC 458 ms
6,940 KB
testcase_04 AC 149 ms
6,944 KB
testcase_05 AC 144 ms
6,944 KB
testcase_06 AC 143 ms
6,940 KB
testcase_07 AC 151 ms
6,944 KB
testcase_08 AC 169 ms
6,940 KB
testcase_09 AC 182 ms
6,940 KB
testcase_10 AC 221 ms
6,944 KB
testcase_11 AC 219 ms
6,940 KB
testcase_12 AC 214 ms
6,944 KB
testcase_13 AC 211 ms
6,940 KB
testcase_14 AC 194 ms
6,940 KB
testcase_15 AC 199 ms
6,940 KB
testcase_16 AC 190 ms
6,944 KB
testcase_17 AC 195 ms
6,940 KB
testcase_18 AC 191 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

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;
}

typedef long long ll;
ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

const int mod = 100003;

int main(){
    int n, q;
    cin >> n >> q;
    int a[n];
    generateA(n, a);
    bool b[100004] = {};
    for(int i = 0; i < n; i++)  b[a[i]] = true;
    bool f = (ll)n*q < 5e7;
    while(q--){
        ll x;
        cin >> x;
        if(x == 0){
            cout << 0 << endl;
            continue;
        }
        int ans = 0;
        if(f){
            for(int i = 0; i < n; i++)  ans = max(ans, (int)(x*a[i]%mod));
        }else{
            int inv = modpow(x, mod-2, mod);
            for(ans = 100002;;ans--){
                if(b[(ll)ans*inv%mod])  break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0