結果

問題 No.97 最大の値を求めるくえり
ユーザー mamekinmamekin
提出日時 2015-02-01 04:15:12
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 98,564 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-05 08:57:40
合計ジャッジ時間 9,294 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
4,376 KB
testcase_01 AC 12 ms
4,380 KB
testcase_02 AC 1,415 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

unsigned xor128()
{
    static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}
void generateA(int N, vector<int>& A)
{
    A.resize(N);
    for(int i = 0; i < N; ++ i)
        A[i] = xor128() % 100003;
}

const int MOD = 100003;

void mod_inverse(int n, vector<long long>& inv)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
}

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> a;
    generateA(n, a);
    sort(a.begin(), a.end());

    vector<long long> inv;
    mod_inverse(MOD-1, inv);
    while(--q >= 0){
        long long x;
        cin >> x;
        if(x == 0){
            cout << 0 << endl;
            continue;
        }
        for(int b=100002; ; --b){
            int tmp = b * inv[q] % MOD;
            if(binary_search(a.begin(), a.end(), b * inv[x] % MOD)){
                cout << b << endl;
                break;
            }
        }
    }

    return 0;
}
0