結果

問題 No.97 最大の値を求めるくえり
ユーザー simezi_tansimezi_tan
提出日時 2014-12-09 00:49:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 880 ms / 5,000 ms
コード長 1,759 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 157,988 KB
実行使用メモリ 220,676 KB
最終ジャッジ日時 2023-09-02 11:56:49
合計ジャッジ時間 13,379 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,148 KB
testcase_01 AC 703 ms
220,672 KB
testcase_02 AC 591 ms
10,512 KB
testcase_03 AC 608 ms
10,448 KB
testcase_04 AC 234 ms
8,956 KB
testcase_05 AC 264 ms
8,876 KB
testcase_06 AC 298 ms
8,892 KB
testcase_07 AC 406 ms
8,956 KB
testcase_08 AC 443 ms
9,320 KB
testcase_09 AC 479 ms
9,520 KB
testcase_10 AC 525 ms
10,424 KB
testcase_11 AC 520 ms
11,000 KB
testcase_12 AC 625 ms
11,760 KB
testcase_13 AC 669 ms
12,008 KB
testcase_14 AC 660 ms
15,428 KB
testcase_15 AC 513 ms
24,320 KB
testcase_16 AC 436 ms
38,824 KB
testcase_17 AC 647 ms
133,628 KB
testcase_18 AC 880 ms
220,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

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


const int N = 100003;
int n, q, a[N];
unordered_set<int> xs[N];

inline ll inv(ll a)
{
	ll b = N, x = 1, y = 0;
	while(b){
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		x -= t * y;
		swap(x, y);
	}
	return (N + x % N) % N;
}


int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> q;
	generateA(n, a);
	
	vi v;
	rep(i, n) if(a[i]) v.pb(inv(a[i]));
	sort(all(v)); v.erase(unique(all(v)), v.end());
	
	const int B = 80;
	for(int i = N - 1; i >= N - B; i--){
		for(int j : v) xs[i].insert(i * (ll)j % N);
	}
	
	rep(it, q){
		int x; cin >> x;
		if(x == 0){
			cout << 0 << endl;
			continue;
		}
		
		bool ok = 0;
		for(int i = N - 1; i >= N - B; i--) if(xs[i].count(x)){
			ok = 1;
			cout << i << endl;
			break;
		}
		if(!ok){
			int mx = 0;
			rep(i, n) mx = max((ll)mx, a[i] * (ll)x % N);
			cout << mx << endl;
		}
	}
	
	return 0;
}
0