結果

問題 No.20 砂漠のオアシス
ユーザー chocoruskchocorusk
提出日時 2018-10-17 04:36:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 89,404 KB
実行使用メモリ 66,192 KB
最終ジャッジ日時 2023-08-02 20:38:12
合計ジャッジ時間 4,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 6 ms
5,752 KB
testcase_04 AC 20 ms
8,584 KB
testcase_05 AC 72 ms
63,280 KB
testcase_06 AC 24 ms
8,980 KB
testcase_07 AC 1,137 ms
66,192 KB
testcase_08 AC 125 ms
19,900 KB
testcase_09 AC 482 ms
52,420 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 13 ms
6,380 KB
testcase_14 AC 58 ms
11,272 KB
testcase_15 AC 28 ms
9,120 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 95 ms
18,052 KB
testcase_20 AC 7 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

int n, v, ox, oy;
bool used[2][201][201][1001];
int l[201][201];
int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};

void dfs(int i, int x, int y, int w){
	used[i][x][y][w]=1;
	for(int k=0; k<4; k++){
		if(0<x+dx[k] && x+dx[k]<=n && 0<y+dy[k] && y+dy[k]<=n && w>l[x+dx[k]][y+dy[k]]){
			if(!used[i][x+dx[k]][y+dy[k]][w-l[x+dx[k]][y+dy[k]]]) dfs(i, x+dx[k], y+dy[k], w-l[x+dx[k]][y+dy[k]]);
			if(i==0 && x+dx[k]==ox && y+dy[k]==oy){
				if(!used[i+1][x+dx[k]][y+dy[k]][2*(w-l[x+dx[k]][y+dy[k]])]) dfs(i+1, x+dx[k], y+dy[k], 2*(w-l[x+dx[k]][y+dy[k]]));
			}
		}
	}
}

int main()
{
	cin>>n>>v>>ox>>oy;
	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) cin>>l[i][j];
	dfs(0, 1, 1, v);
	bool ok=0;
	for(int i=0; i<2; i++){
		for(int j=1; j<=2*v; j++){
			if(used[i][n][n][j]){
				ok=1;
				break;
			}
		}
		if(ok) break;
	}
	if(ok) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}
0