結果

問題 No.612 Move on grid
ユーザー Sebastian KingSebastian King
提出日時 2017-12-12 23:57:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 280 ms / 2,500 ms
コード長 2,438 bytes
コンパイル時間 1,197 ms
コンパイル使用メモリ 146,776 KB
実行使用メモリ 210,080 KB
最終ジャッジ日時 2023-08-22 22:16:54
合計ジャッジ時間 7,542 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
188,512 KB
testcase_01 AC 219 ms
188,516 KB
testcase_02 AC 219 ms
188,700 KB
testcase_03 AC 225 ms
189,768 KB
testcase_04 AC 254 ms
209,992 KB
testcase_05 AC 278 ms
210,068 KB
testcase_06 AC 277 ms
210,044 KB
testcase_07 AC 256 ms
210,080 KB
testcase_08 AC 280 ms
209,996 KB
testcase_09 AC 254 ms
199,540 KB
testcase_10 AC 245 ms
196,528 KB
testcase_11 AC 230 ms
190,684 KB
testcase_12 AC 253 ms
200,928 KB
testcase_13 AC 237 ms
192,744 KB
testcase_14 AC 264 ms
204,912 KB
testcase_15 AC 231 ms
191,272 KB
testcase_16 AC 271 ms
207,708 KB
testcase_17 AC 234 ms
192,896 KB
testcase_18 AC 263 ms
204,072 KB
testcase_19 AC 241 ms
197,664 KB
testcase_20 AC 252 ms
201,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

void prework(){

}

void read(){

}

ll n, P;
ll MAGIC0, MAGIC1;

void precalc(){
    __int128 x = (((__int128)1)<<63) - (((__int128)1)<<63)%P - 1,t;
    for(MAGIC1=0;t=((__int128)1)<<MAGIC1,t<=x*(P-t%P);MAGIC1++);
    if(MAGIC1 < 64) MAGIC1 = 64, t = ((__int128)1)<<64;
    MAGIC0 = (t+P-t%P)/P;
}

long long mod(long long x){
    long long t = ((__int128)x) * MAGIC0 >> 64;
    if (MAGIC0 < 0) t += x;
    return x - (t >> (MAGIC1 - 64)) * P;
}

int f[70000000];

namespace nico{

int a, b, c, d, e;
int T;

int f[502][20010];

void upd(int &x, int y){
	x += y;
	if (x >= MM) x -= MM;
}

void gao(){
//	cout << "Case #" << casi << ": ";
	cin >> T;
	cin >> a >> b >> c >> d >> e;
	f[0][10000] = 1;
	for (int i = 1; i <= T; i++){
		for (int j = 0; j <= 20000; j++)
			if (f[i-1][j]){
				upd(f[i][j+a], f[i-1][j]);
				upd(f[i][j+b], f[i-1][j]);
				upd(f[i][j+c], f[i-1][j]);
				upd(f[i][j-a], f[i-1][j]);
				upd(f[i][j-b], f[i-1][j]);
				upd(f[i][j-c], f[i-1][j]);
			}
	}
	ll ans = 0;
	for (int i = d + 10000; i <= e + 10000; i++){
		ans += f[T][i];
	}
	cout << ans % MM << endl;
}

}


void solve(int casi){
//	cout << "Case #" << casi << ": ";
	
	n=1000000000000000000ll,P=800000011ll;
	
	if (P == 2){
		cout << 0 << endl;
		return ;
	}
	//f[0] = 1;
	ll x = 2;
	precalc();
	ll T, G, U;
	int flag = 0;
	n++;
	if (P < 70000000){
		for (int i = 2; i <= n; i++){
			x = mod(x * (x + 4));
			if (f[x]){
				flag = 1;
				T = (i - f[x]);
				G = f[x];
				U = x;
				break;
			}
			else{
				f[x] = i;
			}
		}
	}
	else{
		for (int i = 2; i <= n; i++){
			x = mod(x * (x + 4));
			//cerr << x << ' ' << (x >> 4) <<endl;
			if ((x & 15)==0){
				if (f[x >> 4]){
					flag = 1;
					T = (i - f[x >> 4]);
					G = f[x >> 4];
					U = x;
					break;
				}
				else{
					f[x >> 4] = i;
				}
			}
		}
	}
	//cout << T << endl;
	//cout << flag << ' ' << T << ' ' << G << ' ' << U << endl;
	if (flag){
		x = U;
		ll i = (n - G) % T;
		for (; i; i--){
			x = mod(x * (x + 4));
		}
		//cout << x << endl;
		if (x != -1)
			nico::gao();
	}
	else{
		if (x != -1)
			nico::gao();
	}
}

void printans(){

}


int main(){
	std::ios::sync_with_stdio(false);
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}

0