結果
| 問題 | 
                            No.97 最大の値を求めるくえり
                             | 
                    
| コンテスト | |
| ユーザー | 
                             imgry22
                         | 
                    
| 提出日時 | 2015-01-08 03:01:53 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,921 bytes | 
| コンパイル時間 | 1,588 ms | 
| コンパイル使用メモリ | 159,468 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-13 03:12:25 | 
| 合計ジャッジ時間 | 6,669 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 13 WA * 6 | 
ソースコード
#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 != 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 == 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, N) if(exist[(int)(i * mi % MOD)]){ mx = i;  break; }
    cout << mx << endl;
  }
  return 0;
}
            
            
            
        
            
imgry22