結果

問題 No.97 最大の値を求めるくえり
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2024-01-02 15:19:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,363 ms / 5,000 ms
コード長 2,210 bytes
コンパイル時間 5,513 ms
コンパイル使用メモリ 319,980 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-01-02 15:20:18
合計ジャッジ時間 21,759 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,676 KB
testcase_01 AC 28 ms
7,296 KB
testcase_02 AC 948 ms
10,496 KB
testcase_03 AC 199 ms
6,676 KB
testcase_04 AC 161 ms
6,676 KB
testcase_05 AC 160 ms
6,676 KB
testcase_06 AC 160 ms
6,676 KB
testcase_07 AC 169 ms
6,676 KB
testcase_08 AC 2,363 ms
14,592 KB
testcase_09 AC 2,012 ms
14,592 KB
testcase_10 AC 1,536 ms
14,592 KB
testcase_11 AC 1,288 ms
14,592 KB
testcase_12 AC 1,157 ms
14,592 KB
testcase_13 AC 1,049 ms
14,592 KB
testcase_14 AC 819 ms
14,592 KB
testcase_15 AC 563 ms
14,848 KB
testcase_16 AC 524 ms
15,104 KB
testcase_17 AC 436 ms
16,768 KB
testcase_18 AC 439 ms
18,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>


using namespace std;
using namespace atcoder;
#define rep(i,m,n,k) for (int i = (int)(m); i < (int)(n); i += (int)(k))
#define rrep(i,m,n,k) for (int i = (int)(m); i > (int)(n); i += (int)(k))
#define ll long long
#define list(T,A,N) vector<T> A(N);for(int i=0;i<(int)(N);i++){cin >> A[i];}
#define int long long
int power_mod(int n, int k, int mod) {
    int result = 1;
    // k を右シフトしつつ n を 2 乗していく
    while (k > 0) {
        // k の最下ビットが 1 なら、今の n を答えに掛ける
        if ((k & 1) == 1) result = (result * n) % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return result;
}
template <class T>
map<T,ll> Counter(vector<T> A){
    map<T,ll> m;
    for(auto a:A) m[a]++;
    return 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;
}
using mint = static_modint<100003>;
const int mod = 100003;
signed main(){
    
    int N,Q;
    cin >> N >> Q;
    map<int,int> mem;
    set<int> S;
    set<int> SA;
    int A[N];
    generateA(N,A);
    int q;
    int ans;
    for(int a:A) SA.insert(a);
    S.insert(0);
    mem[0] = 0;
    if (N<100){
        rep(_,0,Q,1){
            cin >> q;
            ans = 0;
            for(int a:A){
                ans = max(ans,a*q%mod);
            }
            cout << ans << endl;
        }
        return 0;
    }
    else{
        int inv;
        rep(_,0,Q,1){
            cin >> q;
            if (S.count(q)){
                cout << mem[q] << endl;
                continue;
            }
            S.insert(q);
            inv = power_mod(q,mod-2,mod);
            rrep(i,mod-1,-1,-1){
                if(SA.count(inv*i%mod)){
                    mem[q] = i;
                    break;
                }
            }
            cout << mem[q] << endl;
        }
        return 0;
    }


    
}
0