結果

問題 No.308 素数は通れません
ユーザー pekempeypekempey
提出日時 2015-12-01 00:27:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,713 bytes
コンパイル時間 1,245 ms
コンパイル使用メモリ 157,704 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-12 06:06:46
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<class T>
T parse(string s) {
	istringstream iss(s);
	T res;
	iss >> res;
	return res;
}

bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return n != 1;
}

bool check(int n, int w) {
	queue<pair<int, int>> q;
	vector<vector<char>> vis(n + 1, vector<char>(w));
	q.emplace(0, 0);
	vis[0][0] = true;
	n--;
	while (!q.empty()) {
		int y, x;
		tie(y, x) = q.front(); q.pop();
		int dy[] = {0, 1, 0, -1};
		int dx[] = {1, 0, -1, 0};
		rep (k, 4) {
			int ny = y + dy[k];
			int nx = x + dx[k];
			int nv = ny * w + nx;
			if (ny < 0 || nx < 0 || nx >= w || nv > n) continue;
			if (isprime(nv + 1)) continue;
			if (vis[ny][nx]) continue;
			vis[ny][nx] = true;
			q.emplace(ny, nx);
		}
	}
	return vis[n / w][n % w];
}

int main() {
	string N;
	cin >> N;
	int m = 0;
	rep (i, N.length()) {
		m = (m * 10 + (N[i] - '0')) % 6;
	}
	if (m == 2 || m == 4) {
		cout << 6 << endl;
	} else if (N.length() >= 3) {
		cout << 8 << endl;
	} else {
		int n = parse<int>(N);
		int ans = 1;
		while (!check(n, ans)) ans++;
		cout << ans << endl;
	}
	return 0;
}
0