結果

問題 No.97 最大の値を求めるくえり
ユーザー natsugirnatsugir
提出日時 2014-12-07 20:33:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,657 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 64,420 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-02 09:46:38
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 119 ms
4,380 KB
testcase_03 AC 119 ms
4,376 KB
testcase_04 AC 20 ms
4,384 KB
testcase_05 AC 22 ms
4,380 KB
testcase_06 AC 22 ms
4,380 KB
testcase_07 AC 31 ms
4,380 KB
testcase_08 AC 41 ms
4,376 KB
testcase_09 AC 61 ms
4,380 KB
testcase_10 AC 100 ms
4,376 KB
testcase_11 AC 138 ms
4,380 KB
testcase_12 AC 177 ms
4,376 KB
testcase_13 AC 780 ms
4,376 KB
testcase_14 AC 448 ms
4,376 KB
testcase_15 AC 223 ms
4,380 KB
testcase_16 AC 139 ms
4,380 KB
testcase_17 AC 68 ms
4,380 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
	    LL inv_q = powMod(q, MOD-2, MOD);
	    int ans;
	    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;
}
0