結果
| 問題 |
No.97 最大の値を求めるくえり
|
| コンテスト | |
| ユーザー |
sugim48
|
| 提出日時 | 2014-12-07 21:36:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,941 bytes |
| コンパイル時間 | 735 ms |
| コンパイル使用メモリ | 89,180 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-06-11 17:26:32 |
| 合計ジャッジ時間 | 9,987 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 TLE * 1 -- * 5 |
ソースコード
#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);
set<int> s;
for (int i = 0; i < N; i++)
s.insert(A[i]);
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 (s.count(p * x % 100003)) {
cout << x << endl;
break;
}
}
}
}
sugim48