結果

問題 No.97 最大の値を求めるくえり
ユーザー imgry22imgry22
提出日時 2015-01-08 03:12:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 340 ms / 5,000 ms
コード長 1,919 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 145,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 22:36:16
合計ジャッジ時間 6,795 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 282 ms
4,380 KB
testcase_03 AC 283 ms
4,380 KB
testcase_04 AC 182 ms
4,376 KB
testcase_05 AC 185 ms
4,376 KB
testcase_06 AC 185 ms
4,384 KB
testcase_07 AC 195 ms
4,380 KB
testcase_08 AC 203 ms
4,380 KB
testcase_09 AC 228 ms
4,376 KB
testcase_10 AC 263 ms
4,380 KB
testcase_11 AC 298 ms
4,376 KB
testcase_12 AC 340 ms
4,380 KB
testcase_13 AC 208 ms
4,376 KB
testcase_14 AC 200 ms
4,376 KB
testcase_15 AC 195 ms
4,376 KB
testcase_16 AC 192 ms
4,376 KB
testcase_17 AC 190 ms
4,376 KB
testcase_18 AC 192 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;

#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(ll (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 10000000000
#define MOD 100003LL
#define EPS 1E-9

const int MAX_N = 100003;
const int MAX_Q = 100003;
int N, Q;
int A[MAX_N];
bool exist[MAX_N];
ll q;

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;
}


ll extgcd(ll a, ll b, ll& x, ll& y)
{
  ll d = a;
  if(b != 0){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  else{
    x = 1;
    y = 0;
  }
  return d;
}

ll modInverse(ll a, ll m)
{
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}


int main()
{
  cin >> N >> Q;

  generateA(N, A);
  rep(i, N) exist[A[i]] = true;

  while(Q--){
    cin >> q;

    if(q == 0LL){
      cout << 0 << endl;
      continue;
    }

    ll mx = 0LL;
    ll mi = modInverse(q, MOD);
    if(N < 1000) rep(i, N) maxup(mx, (A[i] * q) % MOD);
    else rev(i, MAX_N) if(exist[(int)(i * mi % MOD)]){ mx = i;  break; }
    cout << mx << endl;
  }

  return 0;
}
0