結果

問題 No.97 最大の値を求めるくえり
ユーザー beetbeet
提出日時 2019-03-23 14:18:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,769 ms / 5,000 ms
コード長 1,850 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 210,896 KB
実行使用メモリ 4,764 KB
最終ジャッジ日時 2023-10-23 18:11:50
合計ジャッジ時間 7,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 12 ms
4,764 KB
testcase_02 AC 109 ms
4,348 KB
testcase_03 AC 109 ms
4,348 KB
testcase_04 AC 17 ms
4,348 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 19 ms
4,348 KB
testcase_07 AC 26 ms
4,348 KB
testcase_08 AC 36 ms
4,348 KB
testcase_09 AC 54 ms
4,348 KB
testcase_10 AC 90 ms
4,348 KB
testcase_11 AC 126 ms
4,348 KB
testcase_12 AC 161 ms
4,348 KB
testcase_13 AC 200 ms
4,348 KB
testcase_14 AC 381 ms
4,348 KB
testcase_15 AC 918 ms
4,348 KB
testcase_16 AC 1,769 ms
4,348 KB
testcase_17 AC 36 ms
4,568 KB
testcase_18 AC 38 ms
4,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

//INSERT ABOVE HERE

const int BS = 10000;
const int MOD = 100003;

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));
}
vector<int> generateA(int N) {
  vector<int> A(N);
  for(int i = 0; i < N; ++ i)
    A[i] = xor128() % MOD;
  return A;
}

signed main(){
  int n,q;
  cin>>n>>q;
  auto a=generateA(n);
  using ll = long long;
  a=compress(a);
  n=a.size();
  if(n<=BS){
    while(q--){
      ll x;
      cin>>x;
      ll res=0;
      for(int y:a) chmax(res,x*y%MOD);
      cout<<res<<"\n";
    }
    cout<<flush;
    return 0;
  }
  auto inv=[](ll x)->ll{
             ll n=MOD-2,res=1;             
             while(n){
               if(n&1) res=res*x%MOD;
               x=x*x%MOD;
               n>>=1;
             }
             return res;
           };
  vector<int> exist(MOD,0);
  for(int y:a) exist[y]=1;

  vector<ll> memo(MOD,-1);
  memo[0]=0;
  while(q--){
    ll x;
    cin>>x;   
    ll &res=memo[x];    
    if(~res){
      cout<<res<<"\n";
      continue;
    }
    res=MOD-1;
    ll z=inv(x);
    ll tmp=res*z%MOD;
    while(!exist[tmp]){
      res--;
      tmp-=z;
      if(tmp<0) tmp+=MOD;
    }
    cout<<res<<"\n";
  }
  cout<<flush;
  return 0;
}
0