結果
問題 | No.97 最大の値を求めるくえり |
ユーザー |
![]() |
提出日時 | 2014-12-07 19:45:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,349 ms / 5,000 ms |
コード長 | 4,646 bytes |
コンパイル時間 | 882 ms |
コンパイル使用メモリ | 97,916 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-11 16:15:23 |
合計ジャッジ時間 | 7,187 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#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){bool submit = true;ll N,Q;inp >> N >> Q;vl qs(Q);rep(i,Q) inp >> qs[i];if(!submit){rep(i,100003)qs.push_back(i);}double start = get_time();vi a(N);generateA(N,a);rep(i,10)debug(a[i]);vi h(mod);for(int v:a){h[v]=1;}ll tot=0;if(N>=2000){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;}tot += v;if(submit){cout << v << endl;}}}else{for(ll q:qs){ll maxi = -1;for(int v:a) maxi = max(maxi, (q*v)%100003);tot += maxi;if(submit)cout << maxi << endl;}}debug(get_time()-start);debug(tot);}int main(){if(0){ifstream ifs("test.txt");_main(ifs);}else{_main(cin);}return 0;}