結果

問題 No.308 素数は通れません
ユーザー hirokazu1020hirokazu1020
提出日時 2015-12-05 21:26:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,779 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 99,524 KB
実行使用メモリ 43,684 KB
最終ジャッジ日時 2023-10-12 15:49:11
合計ジャッジ時間 15,908 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
26,116 KB
testcase_01 AC 89 ms
26,024 KB
testcase_02 AC 91 ms
26,064 KB
testcase_03 AC 91 ms
25,920 KB
testcase_04 AC 90 ms
26,156 KB
testcase_05 AC 92 ms
25,936 KB
testcase_06 AC 92 ms
25,932 KB
testcase_07 AC 89 ms
25,912 KB
testcase_08 AC 88 ms
25,972 KB
testcase_09 AC 89 ms
25,912 KB
testcase_10 AC 95 ms
25,856 KB
testcase_11 AC 95 ms
25,852 KB
testcase_12 AC 89 ms
25,856 KB
testcase_13 AC 97 ms
25,908 KB
testcase_14 AC 98 ms
26,140 KB
testcase_15 AC 90 ms
25,912 KB
testcase_16 AC 90 ms
26,144 KB
testcase_17 AC 89 ms
26,140 KB
testcase_18 AC 90 ms
25,856 KB
testcase_19 AC 90 ms
25,864 KB
testcase_20 AC 90 ms
26,152 KB
testcase_21 AC 90 ms
25,996 KB
testcase_22 AC 90 ms
25,932 KB
testcase_23 AC 90 ms
25,940 KB
testcase_24 AC 89 ms
25,860 KB
testcase_25 AC 89 ms
25,880 KB
testcase_26 AC 90 ms
25,908 KB
testcase_27 AC 90 ms
25,864 KB
testcase_28 AC 89 ms
25,936 KB
testcase_29 AC 88 ms
25,916 KB
testcase_30 AC 88 ms
25,868 KB
testcase_31 AC 88 ms
25,916 KB
testcase_32 AC 91 ms
26,156 KB
testcase_33 AC 88 ms
25,988 KB
testcase_34 AC 88 ms
25,864 KB
testcase_35 AC 89 ms
25,860 KB
testcase_36 AC 89 ms
25,920 KB
testcase_37 AC 89 ms
25,860 KB
testcase_38 AC 89 ms
25,856 KB
testcase_39 AC 89 ms
26,064 KB
testcase_40 AC 88 ms
25,908 KB
testcase_41 AC 87 ms
25,944 KB
testcase_42 AC 88 ms
25,860 KB
testcase_43 AC 87 ms
25,944 KB
testcase_44 AC 88 ms
25,860 KB
testcase_45 AC 93 ms
25,944 KB
testcase_46 AC 89 ms
25,940 KB
testcase_47 AC 91 ms
25,940 KB
testcase_48 AC 91 ms
25,944 KB
testcase_49 AC 90 ms
25,888 KB
testcase_50 AC 89 ms
25,940 KB
testcase_51 AC 89 ms
25,892 KB
testcase_52 AC 89 ms
26,004 KB
testcase_53 AC 90 ms
26,012 KB
testcase_54 AC 89 ms
25,868 KB
testcase_55 AC 89 ms
25,900 KB
testcase_56 AC 92 ms
26,400 KB
testcase_57 AC 91 ms
26,000 KB
testcase_58 AC 97 ms
28,460 KB
testcase_59 AC 135 ms
43,536 KB
testcase_60 AC 135 ms
43,536 KB
testcase_61 AC 134 ms
43,544 KB
testcase_62 AC 135 ms
43,476 KB
testcase_63 AC 135 ms
43,400 KB
testcase_64 AC 134 ms
43,452 KB
testcase_65 AC 136 ms
43,388 KB
testcase_66 AC 136 ms
43,404 KB
testcase_67 AC 135 ms
43,476 KB
testcase_68 AC 137 ms
43,420 KB
testcase_69 AC 136 ms
43,680 KB
testcase_70 AC 137 ms
43,472 KB
testcase_71 AC 137 ms
43,540 KB
testcase_72 AC 136 ms
43,400 KB
testcase_73 AC 137 ms
43,456 KB
testcase_74 AC 137 ms
43,540 KB
testcase_75 AC 137 ms
43,420 KB
testcase_76 AC 96 ms
26,108 KB
testcase_77 AC 92 ms
26,204 KB
testcase_78 AC 123 ms
38,184 KB
testcase_79 AC 136 ms
43,476 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 135 ms
43,476 KB
testcase_83 AC 135 ms
43,444 KB
testcase_84 WA -
testcase_85 AC 136 ms
43,484 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 135 ms
43,652 KB
testcase_89 AC 136 ms
43,396 KB
testcase_90 WA -
testcase_91 AC 136 ms
43,488 KB
testcase_92 AC 135 ms
43,408 KB
testcase_93 AC 137 ms
43,412 KB
testcase_94 AC 135 ms
43,420 KB
testcase_95 AC 136 ms
43,536 KB
testcase_96 AC 134 ms
43,532 KB
testcase_97 AC 134 ms
43,680 KB
testcase_98 AC 134 ms
43,484 KB
testcase_99 AC 134 ms
43,448 KB
testcase_100 AC 134 ms
43,448 KB
testcase_101 WA -
testcase_102 AC 136 ms
43,472 KB
testcase_103 AC 136 ms
43,532 KB
testcase_104 AC 134 ms
43,536 KB
testcase_105 AC 135 ms
43,452 KB
testcase_106 AC 135 ms
43,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<stack>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


#define MAX_N 10000000
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int sieve(int n) {
	int p = 0;
	memset(is_prime, true, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;
}



long long n;
bool v[MAX_N + 1];

bool f(int w) {
	int dy[] = { -1,0,0,1 };
	int dx[] = { 0,-1,1,0 };
	memset(v, false, sizeof(v));
	v[1] = true;
	stack<pair<int, int>> q;
	int gy = (n - 1) / w, gx = (n - 1) % w;
	q.push(make_pair(0, 0));
	while (!q.empty()) {
		pair<int, int> a, b;
		a = q.top(); q.pop();
		rep(i, 4) {
			b = a;
			b.first += dy[i];
			b.second += dx[i];
			int m = b.first*w + b.second + 1;
			if (n < m || b.first < 0 || b.second < 0 || w <= b.second)continue;
			if (v[m] || is_prime[m])continue;
			v[m] = true;
			q.push(b);
			if (m == n || m>MAX_N - w)return true;
		}
	}

	return false;
}

int main() {
	sieve(MAX_N);
	string s;
	stringstream ss;
	cin >> s;
	if (s.size()>18) {
		n = 1LL << 60;
	}
	else {
		ss << s;
		ss >> n;
	}
	for (int w = 3;; w++) {
		if (f(w)) {
			cout << w << endl;
			break;
		}
	}
	return 0;
}
0