結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 33 ms
6,568 KB
testcase_02 AC 675 ms
4,376 KB
testcase_03 AC 674 ms
4,380 KB
testcase_04 AC 158 ms
4,376 KB
testcase_05 AC 163 ms
4,376 KB
testcase_06 AC 168 ms
4,380 KB
testcase_07 AC 213 ms
4,380 KB
testcase_08 AC 265 ms
4,376 KB
testcase_09 AC 369 ms
4,376 KB
testcase_10 AC 571 ms
4,376 KB
testcase_11 AC 780 ms
4,380 KB
testcase_12 AC 979 ms
4,380 KB
testcase_13 AC 1,183 ms
4,376 KB
testcase_14 AC 740 ms
4,380 KB
testcase_15 AC 478 ms
4,380 KB
testcase_16 AC 372 ms
4,380 KB
testcase_17 AC 293 ms
5,228 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;
}

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

	if (s.size() < 1500){
		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 (s.count(target)){
					ans = i;
					break;
				}
			}

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