結果

問題 No.97 最大の値を求めるくえり
ユーザー 👑 NachiaNachia
提出日時 2020-10-22 21:32:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 1,527 ms
コンパイル使用メモリ 168,388 KB
実行使用メモリ 4,420 KB
最終ジャッジ日時 2023-09-28 14:53:34
合計ジャッジ時間 7,045 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 5 ms
4,412 KB
testcase_02 AC 196 ms
4,376 KB
testcase_03 AC 390 ms
4,380 KB
testcase_04 AC 157 ms
4,380 KB
testcase_05 AC 160 ms
4,384 KB
testcase_06 AC 162 ms
4,376 KB
testcase_07 AC 163 ms
4,376 KB
testcase_08 AC 177 ms
4,380 KB
testcase_09 AC 187 ms
4,380 KB
testcase_10 AC 205 ms
4,388 KB
testcase_11 AC 190 ms
4,380 KB
testcase_12 AC 185 ms
4,376 KB
testcase_13 AC 184 ms
4,380 KB
testcase_14 AC 176 ms
4,412 KB
testcase_15 AC 168 ms
4,380 KB
testcase_16 AC 172 ms
4,380 KB
testcase_17 AC 166 ms
4,420 KB
testcase_18 AC 164 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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