結果

問題 No.20 砂漠のオアシス
ユーザー assy1028assy1028
提出日時 2015-03-21 21:29:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 2,107 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 94,484 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 06:25:00
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 17 ms
6,940 KB
testcase_06 AC 20 ms
6,944 KB
testcase_07 AC 20 ms
6,940 KB
testcase_08 AC 16 ms
6,944 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 6 ms
6,944 KB
testcase_17 AC 5 ms
6,940 KB
testcase_18 AC 5 ms
6,940 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   69 |     scanf("%d%d%d%d", &n, &v, &ox, &oy);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:75:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   75 |             scanf("%d", &l);
      |             ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};

const int inf = 1000000009;
const int MAX = 210*200;
struct edge {
    int to, cost;
};

int V;
vector<edge> G[MAX];
int d[MAX];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, inf);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
	P p = que.top(); que.pop();
	int v = p.second;
	if (d[v] < p.first) continue;
	for (int i = 0; i < G[v].size(); i++) {
	    edge e = G[v][i];
	    if (d[e.to] > d[v] + e.cost) {
		d[e.to] = d[v] + e.cost;
		que.push(P(d[e.to], e.to));
	    }
	}
    }
}

int main() {
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    int n, v, ox, oy;
    scanf("%d%d%d%d", &n, &v, &ox, &oy);
    ox--; oy--;
    V = n * n;
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < n; j++) {
	    int l;
	    scanf("%d", &l);
	    for (int k = 0; k < 4; k++) {
		int x = i + dx[k], y = j + dy[k];
		if (0 <= x && x < n && 0 <= y && y < n) {
		    G[n*x+y].push_back(edge{n*i+j, l});
		}
	    }
	}
    }
    dijkstra(0);
    if (d[n*(n-1)+n-1] < v) {
	printf("YES\n");
    } else {
	if (ox >= 0) {
	    int tv = v - d[n*oy+ox];
	    if (tv <= 0) printf("NO\n");
	    else {
		dijkstra(n*oy+ox);
		if (d[n*(n-1)+n-1] < 2*tv) printf("YES\n");
		else printf("NO\n");
	    }
	} else {
	    printf("NO\n");
	}
    }
}
0