結果

問題 No.308 素数は通れません
ユーザー hirokazu1020hirokazu1020
提出日時 2015-12-03 20:55:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,644 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 103,964 KB
実行使用メモリ 9,176 KB
最終ジャッジ日時 2023-10-12 09:34:30
合計ジャッジ時間 6,912 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,788 KB
testcase_01 AC 7 ms
4,908 KB
testcase_02 AC 7 ms
4,604 KB
testcase_03 AC 7 ms
4,596 KB
testcase_04 AC 7 ms
4,596 KB
testcase_05 AC 7 ms
4,592 KB
testcase_06 AC 7 ms
4,592 KB
testcase_07 AC 7 ms
4,612 KB
testcase_08 AC 7 ms
4,636 KB
testcase_09 AC 7 ms
4,588 KB
testcase_10 AC 7 ms
4,780 KB
testcase_11 AC 6 ms
4,760 KB
testcase_12 AC 7 ms
4,592 KB
testcase_13 AC 7 ms
4,664 KB
testcase_14 AC 7 ms
4,648 KB
testcase_15 AC 6 ms
4,648 KB
testcase_16 AC 7 ms
4,720 KB
testcase_17 AC 7 ms
4,640 KB
testcase_18 AC 7 ms
4,780 KB
testcase_19 AC 7 ms
4,776 KB
testcase_20 AC 7 ms
4,660 KB
testcase_21 AC 7 ms
4,652 KB
testcase_22 AC 7 ms
4,604 KB
testcase_23 AC 7 ms
4,588 KB
testcase_24 AC 7 ms
4,628 KB
testcase_25 AC 7 ms
4,696 KB
testcase_26 AC 7 ms
4,648 KB
testcase_27 AC 7 ms
4,716 KB
testcase_28 AC 7 ms
4,712 KB
testcase_29 AC 7 ms
4,692 KB
testcase_30 AC 7 ms
4,644 KB
testcase_31 AC 7 ms
4,664 KB
testcase_32 AC 7 ms
4,588 KB
testcase_33 AC 7 ms
4,660 KB
testcase_34 AC 6 ms
4,596 KB
testcase_35 AC 7 ms
4,612 KB
testcase_36 AC 7 ms
4,728 KB
testcase_37 AC 7 ms
4,752 KB
testcase_38 AC 7 ms
4,752 KB
testcase_39 AC 7 ms
4,736 KB
testcase_40 AC 7 ms
4,696 KB
testcase_41 AC 7 ms
4,784 KB
testcase_42 AC 7 ms
4,708 KB
testcase_43 AC 8 ms
4,904 KB
testcase_44 AC 7 ms
4,692 KB
testcase_45 AC 8 ms
4,680 KB
testcase_46 AC 8 ms
4,704 KB
testcase_47 AC 8 ms
4,868 KB
testcase_48 AC 8 ms
4,792 KB
testcase_49 AC 9 ms
4,812 KB
testcase_50 AC 9 ms
4,828 KB
testcase_51 AC 9 ms
5,016 KB
testcase_52 AC 10 ms
4,932 KB
testcase_53 AC 10 ms
4,972 KB
testcase_54 AC 10 ms
5,216 KB
testcase_55 AC 10 ms
4,984 KB
testcase_56 AC 49 ms
8,844 KB
testcase_57 AC 49 ms
8,840 KB
testcase_58 AC 49 ms
8,948 KB
testcase_59 AC 49 ms
8,836 KB
testcase_60 AC 50 ms
8,824 KB
testcase_61 AC 49 ms
8,880 KB
testcase_62 AC 48 ms
8,840 KB
testcase_63 AC 49 ms
8,824 KB
testcase_64 AC 49 ms
9,048 KB
testcase_65 AC 49 ms
8,892 KB
testcase_66 AC 49 ms
8,900 KB
testcase_67 AC 49 ms
8,924 KB
testcase_68 AC 49 ms
9,144 KB
testcase_69 AC 49 ms
8,840 KB
testcase_70 AC 50 ms
8,876 KB
testcase_71 AC 49 ms
8,896 KB
testcase_72 AC 50 ms
8,880 KB
testcase_73 AC 48 ms
8,824 KB
testcase_74 AC 49 ms
8,876 KB
testcase_75 AC 49 ms
8,844 KB
testcase_76 AC 60 ms
7,344 KB
testcase_77 AC 49 ms
9,176 KB
testcase_78 AC 49 ms
8,892 KB
testcase_79 AC 49 ms
9,076 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 49 ms
8,928 KB
testcase_83 AC 50 ms
8,924 KB
testcase_84 WA -
testcase_85 AC 49 ms
8,948 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 49 ms
8,868 KB
testcase_89 AC 49 ms
8,844 KB
testcase_90 WA -
testcase_91 AC 50 ms
8,824 KB
testcase_92 AC 49 ms
8,892 KB
testcase_93 AC 49 ms
8,880 KB
testcase_94 AC 49 ms
8,840 KB
testcase_95 AC 49 ms
9,052 KB
testcase_96 AC 50 ms
8,892 KB
testcase_97 AC 49 ms
8,924 KB
testcase_98 AC 49 ms
8,896 KB
testcase_99 AC 49 ms
8,824 KB
testcase_100 AC 49 ms
8,876 KB
testcase_101 WA -
testcase_102 AC 49 ms
8,840 KB
testcase_103 AC 49 ms
8,924 KB
testcase_104 AC 48 ms
8,840 KB
testcase_105 AC 49 ms
8,868 KB
testcase_106 AC 49 ms
8,892 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>
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 1000000
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;
}



int n;


bool f(int w) {
	int dy[] = { 0,1,0,-1 };
	int dx[] = { 1,0,-1,0 };
	set<pair<int, int>> v;
	v.insert(make_pair(0,0));
	queue<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.front(); 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.find(b) != v.end() || is_prime[m])continue;
			v.insert(b);
			q.push(b);
			if (m == n || m>100000)return true;
		}
	}

	return false;
}

int main() {
	sieve(MAX_N);
	cin >> n;
	for (int w = 3;;w++) {
		if (f(w)) {
			cout << w << endl;
			break;
		}
	}
	return 0;
}
0