結果
| 問題 |
No.97 最大の値を求めるくえり
|
| コンテスト | |
| ユーザー |
natsugir
|
| 提出日時 | 2014-12-07 20:40:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 640 ms / 5,000 ms |
| コード長 | 1,720 bytes |
| コンパイル時間 | 565 ms |
| コンパイル使用メモリ | 63,244 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-11 17:04:59 |
| 合計ジャッジ時間 | 4,070 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d%d", &N, &Q);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:49:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
main.cpp:58:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
ソースコード
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
template<class T> inline T &amin(T &a, T b) { if (a>b) a=b; return a; }
template<class T> inline T &amax(T &a, T b) { if (a<b) a=b; return a; }
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 LL MOD = 100003;
LL powMod(LL x, LL y, LL m) {
LL r = 1;
for (; y; y>>=1) {
if (y&1) r = r * x % m;
x = x * x % m;
}
return r;
}
int N, Q;
int A[100111];
int main() {
scanf("%d%d", &N, &Q);
generateA(N, A);
if (N < 1000) {
REP ($, Q) {
int q;
scanf("%d", &q);
int ans = 0;
REP (i, N) amax<int>(ans, (LL)q * A[i] % MOD);
printf("%d\n", ans);
}
} else {
sort(A, A+N);
REP ($, Q) {
int q;
scanf("%d", &q);
int ans;
if (q == 0) {
ans = 0;
} else {
LL inv_q = powMod(q, MOD-2, MOD);
for (ans=MOD-1; ans; ans--) {
LL z = ans * inv_q % MOD;
int p = lower_bound(A, A+N, z) - A;
if (p != N && A[p] == z) {
break;
}
}
}
printf("%d\n", ans);
}
}
return 0;
}
natsugir