結果
問題 | No.20 砂漠のオアシス |
ユーザー | chocorusk |
提出日時 | 2018-10-17 06:06:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 12 ms / 5,000 ms |
コード長 | 2,314 bytes |
コンパイル時間 | 3,397 ms |
コンパイル使用メモリ | 96,960 KB |
実行使用メモリ | 4,388 KB |
最終ジャッジ日時 | 2023-08-02 20:38:23 |
合計ジャッジ時間 | 2,059 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 9 ms
4,380 KB |
testcase_06 | AC | 12 ms
4,380 KB |
testcase_07 | AC | 12 ms
4,376 KB |
testcase_08 | AC | 9 ms
4,380 KB |
testcase_09 | AC | 12 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,384 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 3 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,388 KB |
testcase_16 | AC | 4 ms
4,376 KB |
testcase_17 | AC | 4 ms
4,376 KB |
testcase_18 | AC | 3 ms
4,380 KB |
testcase_19 | AC | 4 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,380 KB |
ソースコード
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <random> using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<P, int> Pint; const int INF=1e9; int main() { int n, v, ox, oy; cin>>n>>v>>ox>>oy; int l[201][201]; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) cin>>l[j][i]; queue<Pint> que[10]; que[0].push(Pint(P(1, 1), 0)); int d[201][201]; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) d[i][j]=INF; d[1][1]=0; int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1}; while(1){ int i0=-1, mn=1e9; for(int i=0; i<10; i++){ if(!que[i].empty()){ if(mn>(que[i].front()).second){ i0=i; mn=(que[i].front()).second; } } } if(i0==-1) break; int x=(que[i0].front()).first.first, y=(que[i0].front()).first.second; que[i0].pop(); if(mn>d[x][y]) continue; for(int k=0; k<4; k++){ if(0<x+dx[k] && x+dx[k]<=n && 0<y+dy[k] && y+dy[k]<=n){ if(d[x][y]+l[x+dx[k]][y+dy[k]]<d[x+dx[k]][y+dy[k]]){ d[x+dx[k]][y+dy[k]]=d[x][y]+l[x+dx[k]][y+dy[k]]; que[l[x+dx[k]][y+dy[k]]].push(Pint(P(x+dx[k], y+dy[k]), d[x+dx[k]][y+dy[k]])); } } } } if(v>d[n][n]){ cout<<"YES"<<endl; return 0; } if(ox==0 && oy==0){ cout<<"NO"<<endl; return 0; } if(v<=d[ox][oy]){ cout<<"NO"<<endl; return 0; } v=(v-d[ox][oy])*2; que[0].push(Pint(P(ox, oy), 0)); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) d[i][j]=INF; d[ox][oy]=0; while(1){ int i0=-1, mn=1e9; for(int i=0; i<10; i++){ if(!que[i].empty()){ if(mn>(que[i].front()).second){ i0=i; mn=(que[i].front()).second; } } } if(i0==-1) break; int x=(que[i0].front()).first.first, y=(que[i0].front()).first.second; que[i0].pop(); if(mn>d[x][y]) continue; for(int k=0; k<4; k++){ if(0<x+dx[k] && x+dx[k]<=n && 0<y+dy[k] && y+dy[k]<=n){ if(d[x][y]+l[x+dx[k]][y+dy[k]]<d[x+dx[k]][y+dy[k]]){ d[x+dx[k]][y+dy[k]]=d[x][y]+l[x+dx[k]][y+dy[k]]; que[l[x+dx[k]][y+dy[k]]].push(Pint(P(x+dx[k], y+dy[k]), d[x+dx[k]][y+dy[k]])); } } } } if(v>d[n][n]) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }