結果
問題 | No.97 最大の値を求めるくえり |
ユーザー | natsugir |
提出日時 | 2014-12-07 20:40:58 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 825 ms / 5,000 ms |
コード長 | 1,720 bytes |
コンパイル時間 | 817 ms |
コンパイル使用メモリ | 64,712 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-02 10:23:04 |
合計ジャッジ時間 | 5,630 ms |
ジャッジサーバーID (参考情報) |
judge16 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 10 ms
4,380 KB |
testcase_02 | AC | 117 ms
4,376 KB |
testcase_03 | AC | 117 ms
4,376 KB |
testcase_04 | AC | 21 ms
4,376 KB |
testcase_05 | AC | 21 ms
4,376 KB |
testcase_06 | AC | 22 ms
4,376 KB |
testcase_07 | AC | 30 ms
4,376 KB |
testcase_08 | AC | 41 ms
4,380 KB |
testcase_09 | AC | 59 ms
4,376 KB |
testcase_10 | AC | 97 ms
4,380 KB |
testcase_11 | AC | 136 ms
4,376 KB |
testcase_12 | AC | 173 ms
4,380 KB |
testcase_13 | AC | 825 ms
4,376 KB |
testcase_14 | AC | 468 ms
4,384 KB |
testcase_15 | AC | 228 ms
4,380 KB |
testcase_16 | AC | 142 ms
4,380 KB |
testcase_17 | AC | 67 ms
4,376 KB |
testcase_18 | AC | 60 ms
4,380 KB |
ソースコード
#include<cstdio> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<cstring> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0; i<int(n); i++) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) template<class T> inline T &amin(T &a, T b) { if (a>b) a=b; return a; } template<class T> inline T &amax(T &a, T b) { if (a<b) a=b; return a; } 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; } const LL MOD = 100003; LL powMod(LL x, LL y, LL m) { LL r = 1; for (; y; y>>=1) { if (y&1) r = r * x % m; x = x * x % m; } return r; } int N, Q; int A[100111]; int main() { scanf("%d%d", &N, &Q); generateA(N, A); if (N < 1000) { REP ($, Q) { int q; scanf("%d", &q); int ans = 0; REP (i, N) amax<int>(ans, (LL)q * A[i] % MOD); printf("%d\n", ans); } } else { sort(A, A+N); REP ($, Q) { int q; scanf("%d", &q); int ans; if (q == 0) { ans = 0; } else { LL inv_q = powMod(q, MOD-2, MOD); for (ans=MOD-1; ans; ans--) { LL z = ans * inv_q % MOD; int p = lower_bound(A, A+N, z) - A; if (p != N && A[p] == z) { break; } } } printf("%d\n", ans); } } return 0; }