結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 12 ms
4,376 KB
testcase_02 AC 306 ms
4,376 KB
testcase_03 AC 300 ms
4,380 KB
testcase_04 AC 162 ms
4,380 KB
testcase_05 AC 171 ms
4,380 KB
testcase_06 AC 165 ms
4,380 KB
testcase_07 AC 176 ms
4,376 KB
testcase_08 AC 196 ms
4,380 KB
testcase_09 AC 225 ms
4,376 KB
testcase_10 AC 280 ms
4,376 KB
testcase_11 AC 334 ms
4,380 KB
testcase_12 AC 388 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 201 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;
            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