結果

問題 No.97 最大の値を求めるくえり
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-10 20:42:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,359 bytes
コンパイル時間 1,261 ms
コンパイル使用メモリ 155,052 KB
実行使用メモリ 6,964 KB
最終ジャッジ日時 2023-09-17 19:11:43
合計ジャッジ時間 9,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 34 ms
6,964 KB
testcase_02 AC 423 ms
4,380 KB
testcase_03 AC 1,904 ms
4,376 KB
testcase_04 AC 159 ms
4,376 KB
testcase_05 AC 165 ms
4,380 KB
testcase_06 AC 169 ms
4,376 KB
testcase_07 AC 214 ms
4,380 KB
testcase_08 AC 266 ms
4,380 KB
testcase_09 AC 366 ms
4,376 KB
testcase_10 AC 577 ms
4,376 KB
testcase_11 AC 389 ms
4,380 KB
testcase_12 AC 339 ms
4,380 KB
testcase_13 AC 314 ms
4,380 KB
testcase_14 AC 261 ms
4,380 KB
testcase_15 AC 231 ms
4,376 KB
testcase_16 AC 221 ms
4,380 KB
testcase_17 AC 230 ms
5,364 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

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));
}

long long mod = 100003;

long long powmod(long long a, int p){
	if (p == 0) return 1;
	if (p % 2 == 1){
		return a * powmod(a, p - 1) % mod;
	}
	long long c = powmod(a, p / 2);
	return c * c % mod;
}

bool check[100010];

int main(){
	int N, Q;
	cin >> N >> Q;
	vector<long long> a;
	set<long long> s;
	for (int i = 0; i < N; i++)
	{
		a.push_back(xor128() % mod);
		s.insert(a[i]);
		check[(int)a[i]] = true;
	}

	if (s.size() < 500){
		vector<int> nums;
		for (int i: s)
		{
			nums.push_back(i);
		}
		for (int i = 0; i < Q; i++)
		{
			long long query;
			cin >> query;

			long long ans = 0;
			for (auto i: nums)
			{
				ans = max(ans, i * query % mod);
			}
			cout << ans << endl;
		}
	}
	else{
		for (int i = 0; i < Q; i++)
		{
			long long query;
			cin >> query;
			long long rev = powmod(query, mod - 2);
			long long ans = 0;
			for (int i = mod - 1; i >= 0; i--)
			{
				long long target = i * rev % mod;
				if (check[(int)target]){
					ans = i;
					break;
				}
			}

			cout << ans << endl;
		}
	}
}
0