結果

問題 No.97 最大の値を求めるくえり
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-10 20:46:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,973 ms / 5,000 ms
コード長 1,387 bytes
コンパイル時間 1,284 ms
コンパイル使用メモリ 154,928 KB
実行使用メモリ 7,008 KB
最終ジャッジ日時 2023-09-17 19:12:00
合計ジャッジ時間 9,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 33 ms
7,008 KB
testcase_02 AC 433 ms
4,376 KB
testcase_03 AC 1,973 ms
4,376 KB
testcase_04 AC 159 ms
4,376 KB
testcase_05 AC 165 ms
4,376 KB
testcase_06 AC 173 ms
4,380 KB
testcase_07 AC 213 ms
4,380 KB
testcase_08 AC 266 ms
4,384 KB
testcase_09 AC 368 ms
4,376 KB
testcase_10 AC 575 ms
4,376 KB
testcase_11 AC 397 ms
4,376 KB
testcase_12 AC 348 ms
4,376 KB
testcase_13 AC 319 ms
4,380 KB
testcase_14 AC 266 ms
4,380 KB
testcase_15 AC 228 ms
4,380 KB
testcase_16 AC 219 ms
4,380 KB
testcase_17 AC 223 ms
5,292 KB
testcase_18 AC 237 ms
6,736 KB
権限があれば一括ダウンロードができます

ソースコード

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 (target == 0) break;
				if (check[(int)target]){
					ans = i;
					break;
				}
			}

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