結果

問題 No.97 最大の値を求めるくえり
ユーザー KKT89KKT89
提出日時 2019-10-12 23:47:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,954 ms / 5,000 ms
コード長 1,214 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 75,972 KB
実行使用メモリ 5,216 KB
最終ジャッジ日時 2023-08-19 22:33:34
合計ジャッジ時間 9,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 4 ms
4,940 KB
testcase_02 AC 460 ms
4,376 KB
testcase_03 AC 1,954 ms
4,376 KB
testcase_04 AC 142 ms
4,376 KB
testcase_05 AC 146 ms
4,376 KB
testcase_06 AC 152 ms
4,376 KB
testcase_07 AC 191 ms
4,380 KB
testcase_08 AC 249 ms
4,376 KB
testcase_09 AC 776 ms
4,384 KB
testcase_10 AC 513 ms
4,376 KB
testcase_11 AC 422 ms
4,376 KB
testcase_12 AC 377 ms
4,376 KB
testcase_13 AC 350 ms
4,380 KB
testcase_14 AC 295 ms
4,376 KB
testcase_15 AC 258 ms
4,380 KB
testcase_16 AC 247 ms
4,380 KB
testcase_17 AC 242 ms
4,696 KB
testcase_18 AC 241 ms
5,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long int ll;

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(int N, int A[]) {
    for(int i = 0; i < N; ++ i)
        A[i] = xor128() % 100003;
}

ll mod=100003;
ll n,q,a[100030];
ll has[100030];

ll Power(ll a,ll b){
	a%=mod;
 	if(b==0)return 1;
 	if(b==1)return a;
 	ll res=Power(a,b/2);
 	res%=mod;
 	res*=res;
 	res%=mod;
 	if(b%2==1)res*=a;
 	res%=mod;
 	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> q;
	for(int i=0;i<n;i++){
		a[i]=xor128()%mod;
		has[a[i]]++;
	}
	ll ans=0;
	for(int i=0;i<q;i++){
		int x; cin >> x;
		if(x==0){
			cout << 0 << endl;
			continue;
		}
		if(n<=100){
			ans=0;
			for(int i=0;i<n;i++){
				ans=max(ans,(ll)a[i]*x%mod);
			}
		}
		else{
			ll rev=Power(x,mod-2);
			for(ans=100002;ans>=0;ans--){
				if(has[ans*rev%mod])break;
			}
		}
		cout << ans << endl;
	}
}
0