結果

問題 No.308 素数は通れません
ユーザー asi1024asi1024
提出日時 2015-12-15 14:22:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 147,656 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-10-13 17:06:58
合計ジャッジ時間 12,744 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
19,328 KB
testcase_01 AC 83 ms
19,360 KB
testcase_02 AC 81 ms
19,312 KB
testcase_03 AC 81 ms
19,612 KB
testcase_04 AC 77 ms
19,412 KB
testcase_05 AC 78 ms
19,376 KB
testcase_06 AC 81 ms
19,360 KB
testcase_07 AC 81 ms
19,312 KB
testcase_08 AC 80 ms
19,504 KB
testcase_09 AC 79 ms
19,412 KB
testcase_10 AC 77 ms
19,376 KB
testcase_11 AC 79 ms
19,380 KB
testcase_12 AC 81 ms
19,372 KB
testcase_13 AC 80 ms
19,520 KB
testcase_14 AC 80 ms
19,376 KB
testcase_15 AC 79 ms
19,332 KB
testcase_16 AC 79 ms
19,460 KB
testcase_17 AC 82 ms
19,368 KB
testcase_18 AC 81 ms
19,332 KB
testcase_19 AC 77 ms
19,444 KB
testcase_20 AC 81 ms
19,336 KB
testcase_21 AC 82 ms
19,360 KB
testcase_22 AC 83 ms
19,508 KB
testcase_23 AC 82 ms
19,364 KB
testcase_24 AC 80 ms
19,412 KB
testcase_25 AC 78 ms
19,360 KB
testcase_26 AC 79 ms
19,456 KB
testcase_27 AC 83 ms
19,512 KB
testcase_28 AC 79 ms
19,440 KB
testcase_29 AC 80 ms
19,412 KB
testcase_30 AC 80 ms
19,412 KB
testcase_31 AC 77 ms
19,328 KB
testcase_32 AC 80 ms
19,532 KB
testcase_33 AC 77 ms
19,324 KB
testcase_34 AC 79 ms
19,364 KB
testcase_35 AC 77 ms
19,332 KB
testcase_36 AC 77 ms
19,448 KB
testcase_37 AC 82 ms
19,376 KB
testcase_38 AC 82 ms
19,516 KB
testcase_39 AC 78 ms
19,512 KB
testcase_40 AC 80 ms
19,628 KB
testcase_41 AC 78 ms
19,332 KB
testcase_42 AC 80 ms
19,432 KB
testcase_43 AC 80 ms
19,344 KB
testcase_44 AC 80 ms
19,496 KB
testcase_45 AC 80 ms
19,512 KB
testcase_46 AC 83 ms
19,440 KB
testcase_47 AC 80 ms
19,560 KB
testcase_48 AC 89 ms
19,664 KB
testcase_49 AC 79 ms
19,500 KB
testcase_50 AC 82 ms
19,372 KB
testcase_51 AC 81 ms
19,420 KB
testcase_52 AC 78 ms
19,416 KB
testcase_53 AC 79 ms
19,420 KB
testcase_54 AC 78 ms
19,400 KB
testcase_55 AC 77 ms
19,444 KB
testcase_56 AC 80 ms
20,648 KB
testcase_57 AC 77 ms
20,728 KB
testcase_58 AC 77 ms
19,412 KB
testcase_59 AC 77 ms
19,360 KB
testcase_60 AC 79 ms
19,512 KB
testcase_61 AC 80 ms
19,380 KB
testcase_62 AC 77 ms
19,332 KB
testcase_63 AC 79 ms
19,312 KB
testcase_64 AC 76 ms
19,636 KB
testcase_65 AC 77 ms
19,416 KB
testcase_66 AC 81 ms
19,424 KB
testcase_67 AC 79 ms
19,524 KB
testcase_68 AC 80 ms
19,360 KB
testcase_69 AC 81 ms
19,396 KB
testcase_70 AC 79 ms
19,532 KB
testcase_71 AC 82 ms
19,380 KB
testcase_72 AC 80 ms
19,488 KB
testcase_73 AC 77 ms
19,316 KB
testcase_74 AC 79 ms
19,484 KB
testcase_75 AC 78 ms
19,408 KB
testcase_76 AC 84 ms
22,872 KB
testcase_77 AC 79 ms
21,264 KB
testcase_78 AC 76 ms
19,320 KB
testcase_79 AC 78 ms
19,312 KB
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 77 ms
19,376 KB
testcase_83 AC 74 ms
19,444 KB
testcase_84 WA -
testcase_85 AC 76 ms
19,484 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 79 ms
19,356 KB
testcase_89 AC 78 ms
19,380 KB
testcase_90 WA -
testcase_91 AC 82 ms
19,416 KB
testcase_92 AC 77 ms
19,308 KB
testcase_93 AC 77 ms
19,312 KB
testcase_94 AC 79 ms
19,328 KB
testcase_95 AC 77 ms
19,356 KB
testcase_96 AC 78 ms
19,416 KB
testcase_97 AC 76 ms
19,424 KB
testcase_98 AC 78 ms
19,472 KB
testcase_99 AC 78 ms
19,416 KB
testcase_100 AC 78 ms
19,504 KB
testcase_101 WA -
testcase_102 AC 86 ms
19,360 KB
testcase_103 AC 83 ms
19,356 KB
testcase_104 AC 83 ms
19,484 KB
testcase_105 AC 82 ms
19,312 KB
testcase_106 AC 82 ms
19,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef long long ll;

const int SIZE = 16384000;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

bool p[SIZE];

bool dfs(int y, int x, int t, int w, vector<bool> &visited) {
  if (y < 0 || x < 0 || x >= w) return false;
  int n = y * w + x + 1;
  if (n > t) return false;
  if (n == t) return true;
  if (p[n]) return false;
  if (visited[n]) return false;
  visited[n] = true;
  REP(dir,4)
    if (dfs(y + dy[dir], x + dx[dir], t, w, visited))
      return true;
  return false;
}

int solve(string str) {
  if (str.size() >= 7) return 8;
  int N = stoi(str);
  for (int i = 1; i < N; ++i) {
    vector<bool> visited(N+1, false);
    if (dfs(0, 0, N, i, visited)) return i;
  }
  return -1;
}

int main() {
  for (int i = 2; i < SIZE; ++i) p[i] = true;
  for (int i = 2; i*i <= SIZE; ++i)
    if (p[i])
      for (int j = i*i; j <= SIZE; j += i)
        p[j] = false;
  string str;
  cin >> str;
  cout << solve(str) << endl;
  return 0;
}
0