結果

問題 No.97 最大の値を求めるくえり
ユーザー imgry22imgry22
提出日時 2015-01-08 02:46:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 145,328 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-03 22:27:15
合計ジャッジ時間 31,453 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 162 ms
4,384 KB
testcase_05 AC 160 ms
4,380 KB
testcase_06 AC 162 ms
4,384 KB
testcase_07 AC 170 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 196 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(ll (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 != 0LL){
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  else{
    x = 1LL;
    y = 0LL;
  }
  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 == 0){
      cout << 0 << endl;
      continue;
    }

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

  return 0;
}
0