結果
問題 | No.308 素数は通れません |
ユーザー |
![]() |
提出日時 | 2015-12-01 02:13:08 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,584 bytes |
コンパイル時間 | 1,281 ms |
コンパイル使用メモリ | 162,036 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-14 06:17:01 |
合計ジャッジ時間 | 3,783 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 99 WA * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int,int> pii; #define REP(i,n) for(ll i=0;i<n;++i) #define REPR(i,n) for(ll i=1;i<n;++i) #define FOR(i,a,b) for(ll i=a;i<b;++i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define MOD (ll)(1e9+7) #define ADD(a,b) a=((a)+(b))%MOD #define FIX(a) ((a)%MOD+MOD)%MOD #define N_MAX 110 int mp[N_MAX][N_MAX]; bool used[N_MAX][N_MAX]; int n; int vx[4]={1,0,-1,0}; int vy[4]={0,1,0,-1}; bool dfs(int w,int h,int y,int x){ if(y<0||x<0||y>=h||x>=w)return false; if(used[y][x])return false; used[y][x] = true; if(mp[y][x]==1e9)return false; if(mp[y][x]==n)return true; int t = mp[y][x]; bool flag = false; for(int k=2;k*k<=t;++k){ if(t%k==0){ flag = true; break; } } if(t==1)flag = true; if(!flag)return false; REP(i,4){ if( dfs(w,h,y+vy[i],x+vx[i]) ) return true; } return false; } int main(){ string s; cin >> s; if(s.size()>2){ cout << 8 << endl; return 0; } n = atoi(s.c_str()); // if( !(s.size()<=2 && atoi(s.c_str())<30) ){ // cout << 8 << endl; // return 0; // } FOR(w,3,n){ int h = ceil((double)n/w); REP(i,h){ REP(j,w){ if(i*w+j>=n)mp[i][j] = 1e9; else mp[i][j]=i*w+j+1; used[i][j] = false; } } if( dfs(w,h,0,0) ){ cout << w << endl; return 0; } } return 0; }