結果
問題 | No.20 砂漠のオアシス |
ユーザー |
![]() |
提出日時 | 2018-10-17 06:29:48 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 14 ms / 5,000 ms |
コード長 | 2,673 bytes |
コンパイル時間 | 950 ms |
コンパイル使用メモリ | 105,896 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-20 20:43:24 |
合計ジャッジ時間 | 1,688 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 10 ms
6,940 KB |
testcase_06 | AC | 14 ms
6,944 KB |
testcase_07 | AC | 14 ms
6,940 KB |
testcase_08 | AC | 11 ms
6,940 KB |
testcase_09 | AC | 14 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 3 ms
6,940 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 4 ms
6,944 KB |
testcase_18 | AC | 4 ms
6,944 KB |
testcase_19 | AC | 4 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 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; typedef pair<P, P> PP; 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]; priority_queue<PP, vector<PP>, greater<PP>> quefr; que[0].push(Pint(P(1, 1), 0)); quefr.push(PP(P(0, 0), P(1, 1))); 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(!quefr.empty()){ PP p=quefr.top(); quefr.pop(); int i0=p.first.second; que[i0].pop(); if(!que[i0].empty()){ Pint p1=que[i0].front(); quefr.push(PP(P(p1.second, i0), p1.first)); } int x=p.second.first, y=p.second.second; if(p.first.first>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]]; if(que[l[x+dx[k]][y+dy[k]]].empty()){ quefr.push(PP(P(d[x+dx[k]][y+dy[k]], l[x+dx[k]][y+dy[k]]), P(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)); quefr.push(PP(P(0, 0), P(ox, oy))); for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) d[i][j]=INF; d[ox][oy]=0; while(!quefr.empty()){ PP p=quefr.top(); quefr.pop(); int i0=p.first.second; que[i0].pop(); if(!que[i0].empty()){ Pint p1=que[i0].front(); quefr.push(PP(P(p1.second, i0), p1.first)); } int x=p.second.first, y=p.second.second; if(p.first.first>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]]; if(que[l[x+dx[k]][y+dy[k]]].empty()){ quefr.push(PP(P(d[x+dx[k]][y+dy[k]], l[x+dx[k]][y+dy[k]]), P(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; }