結果
| 問題 |
No.308 素数は通れません
|
| コンテスト | |
| ユーザー |
konjo_p
|
| 提出日時 | 2015-12-01 23:21:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 893 bytes |
| コンパイル時間 | 446 ms |
| コンパイル使用メモリ | 59,616 KB |
| 実行使用メモリ | 12,316 KB |
| 最終ジャッジ日時 | 2024-09-14 07:19:55 |
| 合計ジャッジ時間 | 8,596 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 18 RE * 32 TLE * 1 -- * 38 |
ソースコード
#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;
}
konjo_p