結果
問題 | No.97 最大の値を求めるくえり |
ユーザー | hirose_golf |
提出日時 | 2014-12-07 19:34:08 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,397 bytes |
コンパイル時間 | 708 ms |
コンパイル使用メモリ | 97,480 KB |
実行使用メモリ | 11,428 KB |
最終ジャッジ日時 | 2024-06-11 16:10:18 |
合計ジャッジ時間 | 12,859 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
ソースコード
#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> #include <assert.h> #include <sys/time.h> #include <fstream> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define REP(i,n) FOR(i,0,n) #define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define deb(x) cerr << #x << " = " << (x) << " , "; #define debl cerr << " (L" << __LINE__ << ")"<< endl; #define sz(s) (int)((s).size()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizeof(a)) #define pb push_back #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define MP(x,y) make_pair((x),(y)) double pi=3.14159265358979323846; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){ os << "[ "; REP(i,z.size())os << z[i] << ", " ; return ( os << "]" << endl); } template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){ os << "set( "; EACH(p,z)os << (*p) << ", " ; return ( os << ")" << endl); } template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){ os << "{ "; EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ; return ( os << "}" << endl); } template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){ return ( os << "(" << z.first << ", " << z.second << ",)" ); } double get_time(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec*1e-6; } 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, vi&A) { for(int i = 0; i < N; ++ i){ A[i] = ( (ll)xor128() ) % 100003; } } ll mod=100003; struct mint{ ll value; mint():value(0){} mint(ll v):value((v%mod+mod)%mod){} }; mint& operator+=(mint&a, mint b){return a=a.value+b.value;} mint& operator-=(mint&a, mint b){return a=a.value-b.value;} mint& operator*=(mint&a, mint b){return a=a.value*b.value;} mint operator+(mint a, mint b){return a+=b;} mint operator-(mint a, mint b){return a-=b;} mint operator*(mint a, mint b){return a*=b;} mint operator-(mint a){return 0-a;} bool operator==(mint a, mint b){return a.value==b.value;} bool operator!=(mint a, mint b){return a.value!=b.value;} std::ostream& operator<<(std::ostream& os, const mint& m){ return ( os << m.value );} 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 b){ ll x,y; ll d=extgcd(a,b, x, y); assert(d==1); return (x%b+b)%b; } mint& operator/=(mint&a, mint b){return a=a.value*modinverse(b.value,mod);} mint operator/(mint a, mint b){return a/=b;} void _main(istream &inp){ ll N,Q; inp >> N >> Q; vl qs(Q); rep(i,Q) inp >> qs[i]; vi a(N); generateA(N,a); vi h(mod); for(int v:a){ h[v]=1; } if(N*N>=mod){ for(ll q:qs){ if(q==0){ cout << 0 << endl; continue; } int v = mod-1; for(; v>=0; v--) { if( h[ (mint(v)/q).value ] ==1)break; } cout << v << endl; } } else{ for(ll q:qs){ ll maxi = -1; for(int v:a) maxi = max(maxi, (q*v)%100003); cout << maxi << endl; } } } int main(){ if(0){ ifstream ifs("test.txt"); _main(ifs); } else{ _main(cin); } return 0; }