結果
問題 | No.97 最大の値を求めるくえり |
ユーザー |
👑 ![]() |
提出日時 | 2020-10-22 21:32:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 378 ms / 5,000 ms |
コード長 | 1,071 bytes |
コンパイル時間 | 1,772 ms |
コンパイル使用メモリ | 170,688 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 09:35:24 |
合計ジャッジ時間 | 7,018 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include<bits/stdc++.h>using namespace std;using LL = long long;using ULL = unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)const ULL Z = 100003;int N, Q;bool C[Z];vector<ULL> A;ULL I[Z];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() {for (int i = 0; i < N; ++i)C[xor128() % Z] = true;}int main() {cin >> N >> Q;generateA();N = 0; rep(i, Z) if (C[i]) N++;rep(i, Z) if (C[i]) A.push_back(i);I[1] = 1;for (ULL i = 2; i < Z; i++) I[i] = Z - Z / i * I[Z % i] % Z;while (Q--) {ULL q; cin >> q;if (q == 0) { cout << 0 << endl; continue; }if (N < 400) {ULL ans = 0;for (ULL a : A) ans = max(ans, a * q % Z);cout << ans << endl;}else {ULL ans = Z - 1;while (!C[I[q] * ans % Z]) ans--;cout << ans << endl;}}return 0;}