結果

問題 No.97 最大の値を求めるくえり
ユーザー 👑 rin204rin204
提出日時 2022-09-29 21:24:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,018 ms / 5,000 ms
コード長 1,600 bytes
コンパイル時間 4,888 ms
コンパイル使用メモリ 269,104 KB
実行使用メモリ 6,724 KB
最終ジャッジ日時 2023-08-24 05:04:09
合計ジャッジ時間 12,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 25 ms
6,724 KB
testcase_02 AC 814 ms
4,380 KB
testcase_03 AC 815 ms
4,380 KB
testcase_04 AC 20 ms
4,376 KB
testcase_05 AC 27 ms
4,376 KB
testcase_06 AC 34 ms
4,380 KB
testcase_07 AC 98 ms
4,380 KB
testcase_08 AC 177 ms
4,380 KB
testcase_09 AC 335 ms
4,376 KB
testcase_10 AC 654 ms
4,380 KB
testcase_11 AC 970 ms
4,376 KB
testcase_12 AC 1,018 ms
4,376 KB
testcase_13 AC 873 ms
4,380 KB
testcase_14 AC 532 ms
4,380 KB
testcase_15 AC 284 ms
4,376 KB
testcase_16 AC 186 ms
4,380 KB
testcase_17 AC 112 ms
5,488 KB
testcase_18 AC 105 ms
6,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint;

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;
}

void solve(){
    mint::set_mod(100003);
    int n, Q;
    cin >> n >> Q;
    int A[100100];
    generateA(n, A);
    set<int> se;
    for(int i = 0; i < n; i++) se.insert(A[i]);
    bool small = true;
    if (se.size() >= 700){
        small = false;
    }
    for(int i = 0; i < Q; i++){
        int x;
        cin >> x;
        if(x == 0){
            cout << 0 << "\n";
        }
        else if(small){
            int ma = 0;
            for(auto s:se){
                int y = (mint(s) * x).val();
                if(y > ma) ma = y;
            }
            cout << ma << "\n";
        }
        else{
            mint mx = x;            
            mx = mx.inv();
            for(int y = 100002; y > 0; y--){
                if(se.count((mx * y).val())){
                    cout << y << "\n";
                    break;
                }
            }
        }

    }
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t;
    t = 1;
    // cin >> t;
    while(t--) solve();
}




0