結果

問題 No.97 最大の値を求めるくえり
ユーザー mamekinmamekin
提出日時 2015-02-01 04:14:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 875 ms / 5,000 ms
コード長 1,828 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 99,344 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 08:57:26
合計ジャッジ時間 8,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 12 ms
4,384 KB
testcase_02 AC 304 ms
4,376 KB
testcase_03 AC 301 ms
4,376 KB
testcase_04 AC 161 ms
4,376 KB
testcase_05 AC 163 ms
4,380 KB
testcase_06 AC 160 ms
4,376 KB
testcase_07 AC 177 ms
4,380 KB
testcase_08 AC 194 ms
4,380 KB
testcase_09 AC 222 ms
4,380 KB
testcase_10 AC 279 ms
4,380 KB
testcase_11 AC 332 ms
4,376 KB
testcase_12 AC 383 ms
4,376 KB
testcase_13 AC 875 ms
4,376 KB
testcase_14 AC 561 ms
4,376 KB
testcase_15 AC 352 ms
4,376 KB
testcase_16 AC 278 ms
4,376 KB
testcase_17 AC 203 ms
4,380 KB
testcase_18 AC 200 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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());

    if(n < 1000){
        while(--q >= 0){
            long long x;
            cin >> x;
            vector<int> b(n);
            for(int i=0; i<n; ++i)
                b[i] = a[i] * x % MOD;
            cout << *max_element(b.begin(), b.end()) << endl;
        }
    }
    else{
        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