結果

問題 No.97 最大の値を求めるくえり
ユーザー mamekinmamekin
提出日時 2015-02-01 04:02:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,794 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 95,964 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-05 08:54:09
合計ジャッジ時間 33,398 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 9 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
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 xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
	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, 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){
            int 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){
            int 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