結果

問題 No.97 最大の値を求めるくえり
ユーザー simezi_tansimezi_tan
提出日時 2014-12-09 00:42:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,657 bytes
コンパイル時間 3,264 ms
コンパイル使用メモリ 157,520 KB
実行使用メモリ 221,580 KB
最終ジャッジ日時 2023-09-02 11:56:13
合計ジャッジ時間 14,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,944 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 622 ms
11,184 KB
testcase_04 AC 234 ms
9,720 KB
testcase_05 AC 258 ms
9,624 KB
testcase_06 AC 295 ms
9,684 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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

ll inv[N];
void calc(){
	inv[0] = inv[1] = 1;
	for (int i = 2; i < N; i++) inv[i] = (N - N / i * inv[N % i]) % N;
}


int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> q;
	generateA(n, a);
	calc();
	
	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;
		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