結果

問題 No.97 最大の値を求めるくえり
ユーザー mamekinmamekin
提出日時 2015-02-01 04:06:14
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,701 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 94,640 KB
実行使用メモリ 8,312 KB
最終ジャッジ日時 2023-09-05 08:55:33
合計ジャッジ時間 11,813 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 10 ms
4,380 KB
testcase_02 AC 304 ms
4,376 KB
testcase_03 AC 307 ms
4,380 KB
testcase_04 AC 167 ms
4,376 KB
testcase_05 AC 167 ms
4,380 KB
testcase_06 AC 169 ms
4,380 KB
testcase_07 AC 179 ms
4,380 KB
testcase_08 AC 197 ms
4,376 KB
testcase_09 AC 225 ms
4,376 KB
testcase_10 AC 283 ms
4,376 KB
testcase_11 AC 336 ms
4,376 KB
testcase_12 AC 387 ms
4,376 KB
testcase_13 TLE -
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);

    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;
            for(int b=100002; ; --b){
                int tmp = b * inv[q] % MOD;
                if(find(a.begin(), a.end(), b * inv[x] % MOD) != a.end()){
                    cout << b << endl;
                    break;
                }
            }
        }
    }

    return 0;
}
0