結果

問題 No.97 最大の値を求めるくえり
ユーザー chocoruskchocorusk
提出日時 2019-05-26 10:50:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,736 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 100,180 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-10-17 17:52:53
合計ジャッジ時間 7,114 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,504 KB
testcase_02 AC 214 ms
4,504 KB
testcase_03 AC 481 ms
4,504 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 206 ms
4,504 KB
testcase_12 AC 198 ms
4,504 KB
testcase_13 AC 192 ms
4,504 KB
testcase_14 AC 185 ms
4,504 KB
testcase_15 AC 178 ms
4,504 KB
testcase_16 AC 174 ms
4,504 KB
testcase_17 AC 173 ms
4,504 KB
testcase_18 AC 172 ms
4,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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));
}
const ll MOD=100003;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
    int n, Q; cin>>n>>Q;
    ll a[100010];
    bool b[100010]={};
    for(int i=0; i<n; i++){
        a[i]=xor128()%100003;
        b[a[i]]=1;
    }
    int d=500;
    if(n<d){
        for(int i=0; i<Q; i++){
            ll q; cin>>q;
            ll ans=0;
            for(int j=0; j<n; j++){
                ans=max(ans, q*a[i]%MOD);
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    for(int i=0; i<Q; i++){
        ll q; cin>>q;
        if(q==0){
            cout<<0<<endl;
            continue;
        }
        ll qv=inv(q);
        for(int j=MOD-1; j>=0; j--){
            if(b[qv*j%MOD]){
                cout<<j<<endl;
                break;
            }
        }
    }
    return 0;
}
0