結果

問題 No.97 最大の値を求めるくえり
ユーザー koba-e964koba-e964
提出日時 2015-07-28 16:57:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,587 bytes
コンパイル時間 458 ms
コンパイル使用メモリ 53,548 KB
実行使用メモリ 8,672 KB
最終ジャッジ日時 2023-09-23 04:55:47
合計ジャッジ時間 9,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,624 KB
testcase_02 AC 230 ms
4,380 KB
testcase_03 AC 161 ms
4,380 KB
testcase_04 AC 165 ms
4,384 KB
testcase_05 AC 162 ms
4,380 KB
testcase_06 AC 163 ms
4,380 KB
testcase_07 AC 172 ms
4,376 KB
testcase_08 AC 183 ms
4,380 KB
testcase_09 AC 204 ms
4,380 KB
testcase_10 AC 245 ms
4,408 KB
testcase_11 AC 281 ms
4,380 KB
testcase_12 AC 322 ms
4,380 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
	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, int A[]) {
    for(int i = 0; i < N; ++ i)
        A[i] = xor128() % 100003;
}

int a[100005];
int b[100005];
int aset[100005] = {};
int memo[100005];
const ll mod = 100003;

ll invmod(ll x) {
  ll e = mod - 2;
  ll sum = 1;
  ll cur = x;
  while (e > 0) {
    if (e % 2) {
      sum = sum * cur % mod;
    }
    cur = cur * cur % mod;
    e /= 2;
  }
  return sum;
}

ll solve(const int *as, ll q) {
  ll s = mod - 1;
  while (1) {
    if (aset[(s * invmod(q)) % mod]) {
      return s;
    }
    s--;
  }
}

int main(void){
  int n, q;
  cin >> n >> q;
  REP(i, 0, q) {
    cin >> b[i];
  }
  generateA(n, a);
  REP(i, 0, mod) {
    memo[i] = -1;
  }
  if (n >= 1000) {
    REP(i, 0, n) {
      aset[a[i]] = 1;
    }
    REP(i, 0, q) {
      if (memo[b[i]] >= 0) {
	cout << memo[b[i]] << endl;
	continue;
      }
      memo[b[i]] = solve(aset, b[i]);
      cout << memo[b[i]] << endl;
    }
    return 0;
  }
  REP(i, 0, q) {
    if (memo[b[i]] >= 0) {
      cout << memo[b[i]] << endl;
      continue;
    }
    ll ma = 0;
    REP(j, 0, n) {
      ma = max(ma, ((ll)a[j] * (ll)b[i]) % mod);
    }
    cout << ma << endl;
    memo[b[i]] = ma;
  }
}
0