結果

問題 No.97 最大の値を求めるくえり
ユーザー square1001square1001
提出日時 2018-05-28 19:35:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 5,000 ms
コード長 1,061 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 67,936 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 20:12:57
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 51 ms
4,380 KB
testcase_03 AC 264 ms
4,380 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 25 ms
4,376 KB
testcase_08 AC 36 ms
4,376 KB
testcase_09 AC 54 ms
4,376 KB
testcase_10 AC 59 ms
4,380 KB
testcase_11 AC 45 ms
4,380 KB
testcase_12 AC 39 ms
4,380 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 23 ms
4,380 KB
testcase_16 AC 22 ms
4,376 KB
testcase_17 AC 20 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 <= 250) {
			for (int j = 0; j < N; ++j) {
				mx = max(mx, (int)(1LL * A[j] * x % mod));
			}
		}
		else {
			x = inv[x];
			int s = 0;
			for (int j = mod - 1; j >= 0; --j) {
				if (f[s = (s < x ? s - x + mod : s - x)]) {
					mx = j; break;
				}
			}
		}
		cout << mx << '\n';
	}
	return 0;
}
0