結果
問題 |
No.308 素数は通れません
|
ユーザー |
![]() |
提出日時 | 2015-12-01 23:23:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 910 bytes |
コンパイル時間 | 748 ms |
コンパイル使用メモリ | 58,452 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 07:19:59 |
合計ジャッジ時間 | 3,235 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 98 WA * 9 |
ソースコード
#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; return 0; } 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; }