結果

問題 No.97 最大の値を求めるくえり
ユーザー sugim48sugim48
提出日時 2014-12-07 21:37:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,947 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 78,788 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-02 10:46:36
合計ジャッジ時間 10,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 259 ms
4,376 KB
testcase_03 AC 259 ms
4,380 KB
testcase_04 AC 160 ms
4,376 KB
testcase_05 AC 162 ms
4,384 KB
testcase_06 AC 161 ms
4,380 KB
testcase_07 AC 169 ms
4,376 KB
testcase_08 AC 178 ms
4,376 KB
testcase_09 AC 198 ms
4,380 KB
testcase_10 AC 239 ms
4,376 KB
testcase_11 AC 276 ms
4,380 KB
testcase_12 AC 316 ms
4,380 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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 (N < 1000) {
			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