結果

問題 No.97 最大の値を求めるくえり
ユーザー sugim48sugim48
提出日時 2014-12-07 21:42:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 352 ms / 5,000 ms
コード長 1,986 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 79,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 10:50:56
合計ジャッジ時間 6,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 258 ms
4,380 KB
testcase_03 AC 260 ms
4,376 KB
testcase_04 AC 161 ms
4,376 KB
testcase_05 AC 162 ms
4,376 KB
testcase_06 AC 162 ms
4,380 KB
testcase_07 AC 172 ms
4,380 KB
testcase_08 AC 180 ms
4,376 KB
testcase_09 AC 200 ms
4,376 KB
testcase_10 AC 236 ms
4,376 KB
testcase_11 AC 277 ms
4,376 KB
testcase_12 AC 317 ms
4,376 KB
testcase_13 AC 352 ms
4,376 KB
testcase_14 AC 198 ms
4,376 KB
testcase_15 AC 190 ms
4,380 KB
testcase_16 AC 187 ms
4,380 KB
testcase_17 AC 190 ms
4,380 KB
testcase_18 AC 187 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

ll gcd(ll a, ll b) {
	if (b == 0) return abs(a);
	else return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = (a >= 0) ? 1 : -1;
		y = 0;
		return abs(a);
	}
	else {
		ll res = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
		return res;
	}
}

ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

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

int A[100003];

int main() {
	int N, Q; cin >> N >> Q;
	generateA(N, A);
	vector<bool> a(100003);
	for (int i = 0; i < N; i++)
		a[A[i]] = true;
	while (Q--) {
		ll q; cin >> q;
		if (q == 0) cout << 0 << endl;
		else if (N < 2000) {
			ll maxi = 0;
			for (int i = 0; i < N; i++)
				maxi = max(maxi, q * A[i] % 100003);
			cout << maxi << endl;
		}
		else {
			ll p = mod_inverse(q, 100003);
			for (int x = 100002; ; x--)
				if (a[p * x % 100003]) {
					cout << x << endl;
					break;
				}
		}
	}
}
0