結果
| 問題 |
No.97 最大の値を求めるくえり
|
| コンテスト | |
| ユーザー |
square1001
|
| 提出日時 | 2018-05-28 19:10:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,035 bytes |
| コンパイル時間 | 553 ms |
| コンパイル使用メモリ | 69,020 KB |
| 実行使用メモリ | 10,908 KB |
| 最終ジャッジ日時 | 2024-06-30 07:51:35 |
| 合計ジャッジ時間 | 9,368 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 TLE * 1 -- * 1 |
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
const int 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));
}
int N, Q, x, A[100009], inv[100009]; bool f[100009];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
inv[1] = 1;
for (int i = 2; i < mod; ++i) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
cin >> N >> Q;
for (int i = 0; i < N; ++i) A[i] = xor128() % mod, f[A[i]] = true;
for (int i = 0; i < Q; ++i) {
cin >> x;
int mx = -1;
if (x == 0) mx = 0;
else if (N * N <= mod) {
for (int j = 0; j < N; ++j) {
mx = max(mx, (int)(1LL * A[j] * x % mod));
}
}
else {
x = inv[x];
for (int j = mod - 1; j >= 0; --j) {
if (f[1LL * j * x % mod]) {
mx = j; break;
}
}
}
cout << mx << '\n';
}
return 0;
}
square1001