結果

問題 No.308 素数は通れません
ユーザー konjo_pkonjo_p
提出日時 2015-12-01 23:21:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 893 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 59,852 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-12 08:13:57
合計ジャッジ時間 8,257 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,660 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 TLE -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
testcase_100 -- -
testcase_101 -- -
testcase_102 -- -
testcase_103 -- -
testcase_104 -- -
testcase_105 -- -
testcase_106 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;

int table[50][50];

bool solve(int i, int j) {
	if(!(table[i][j]+1))
		return false;
	if(!(table[i][j]-1))
		return true;
	table[i][j]=-1;
	bool res = false;
	const int dxy[] = {1,0,-1,0,1};
	for(int k = 0; k < 4; k++) {
		res |= solve(i+dxy[k],j+dxy[k+1]);
	}
	return res;
}

int main() {
	string n;
	cin >> n;
	if(n.size() >= 3 || atoi(n.c_str()) > 28)
		cout << 8 << endl;

	int N = atoi(n.c_str());
	int w = 1;
	while(1) {
		for(int i = 0; i < 50; i++)
			for(int j = 0; j < 50; j++)
				table[i][j] = -1;
		for(int i = 0; i < N; i++) {
			table[i/w + 1][i%w + 1] = 0;
			bool p = true;
			for(int j = 2; j < i+1; j++) {
				p &= (i+1)%j != 0;
			}
			if(p&&i)
				table[i/w+1][i%w+1] = -1;
		}
		table[(N-1)/w+1][(N-1)%w+1] = 1;
		if(solve(1,1))
			break;
		w++;
	}
	cout << w << endl;
}
0