結果

問題 No.97 最大の値を求めるくえり
ユーザー hirose_golfhirose_golf
提出日時 2014-12-07 19:45:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,759 ms / 5,000 ms
コード長 4,646 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 97,628 KB
実行使用メモリ 4,644 KB
最終ジャッジ日時 2023-09-02 09:28:44
合計ジャッジ時間 8,737 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 256 ms
4,384 KB
testcase_03 AC 255 ms
4,556 KB
testcase_04 AC 160 ms
4,384 KB
testcase_05 AC 158 ms
4,572 KB
testcase_06 AC 161 ms
4,592 KB
testcase_07 AC 166 ms
4,380 KB
testcase_08 AC 179 ms
4,516 KB
testcase_09 AC 196 ms
4,380 KB
testcase_10 AC 240 ms
4,520 KB
testcase_11 AC 275 ms
4,524 KB
testcase_12 AC 313 ms
4,380 KB
testcase_13 AC 351 ms
4,380 KB
testcase_14 AC 1,759 ms
4,456 KB
testcase_15 AC 818 ms
4,500 KB
testcase_16 AC 499 ms
4,464 KB
testcase_17 AC 244 ms
4,376 KB
testcase_18 AC 216 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0