結果
| 問題 | 
                            No.97 最大の値を求めるくえり
                             | 
                    
| コンテスト | |
| ユーザー | 
                             yaoshimax
                         | 
                    
| 提出日時 | 2015-03-09 22:34:44 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,067 bytes | 
| コンパイル時間 | 685 ms | 
| コンパイル使用メモリ | 87,576 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-24 16:59:20 | 
| 合計ジャッジ時間 | 6,165 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 WA * 8 | 
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
#define 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));
}
bool has[100003];
void generateA(int N, int A[]) {
    for(int i = 0; i < N; ++ i)
    {
       A[i] = xor128() % 100003;
      has[A[i]]=true;  
    } 
}
void exgcd(int p, int q, int& a, int& b ){
   // p*a + q*b = 1
   if( q<p ){
      exgcd(q,p,b,a);
      return;
   }
   //now we can safely say p<q
   //p*a+q*b=1, q=cp+r
   //p*a+(cp+r)b=1, p(a+cb)+rb=1
   if( p==0 ){
      a=0;
      b=1;
      return;
   }
   int c = q/p;
   int r = q%p;
   exgcd(p,r,a,b);// a'=(a+cb), b'=b
   a-=c*b;
   return;
}
int rev(int q, int m){
   // return p s.t. pq%mod=1
   // pq = a*mod+1
   // pq-a*mod=1
   int p,a;
   exgcd( q,m,p,a );
//   cout << q<<"*"<<p<<"+"<<m<<"*"<<a<<"=1"<<endl;
   if( p < 0 ){
     p+=((abs(p)+m-1)/m)*m;
   }
   else{
      p%=m;
   }
   return p;
}
int main(){
   int N,Q;
   cin >> N >> Q;
   int A[N];
   generateA(N,A);
   
   for( int i = 0 ; i <Q; i++ ){
      int q;
      cin >> q;
      int y = 0;
      if( N< 500 ){
         for( int i = 0 ; i <N; i++ ){
            y=max(y,A[i]*q%mod);
         }
      }else{
         if( q!= 0){
            int revq=rev(q,mod);
//            cout << revq <<"*"<<q<<"=1"<<endl;
            for( long long i = mod-1; i>= 0 ; i-- ){
               if( has[(i*revq)%mod]){
                  y=i;
                  break;
               }
            }
         }
      }
      printf("%d\n",y);
   }
   
   return 0;
}
            
            
            
        
            
yaoshimax