結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  tottoripaper | 
| 提出日時 | 2014-11-16 10:12:23 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 490 ms / 5,000 ms | 
| コード長 | 1,630 bytes | 
| コンパイル時間 | 1,075 ms | 
| コンパイル使用メモリ | 67,264 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-13 04:58:27 | 
| 合計ジャッジ時間 | 2,609 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     scanf("%d %d %d %d", &N, &V, &OX, &OY);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:20:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |             scanf("%d", &map[y][x]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <iostream>
#include <queue>
#define mp std::make_pair
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int N, V, OX, OY;
int map[201][201], d[201*201][2];
int main(){
    scanf("%d %d %d %d", &N, &V, &OX, &OY);
    for(int y=1;y<=N;y++){
        for(int x=1;x<=N;x++){
            scanf("%d", &map[y][x]);
        }
    }
    std::fill(&d[0][0], &d[0][0]+201*201*2, -1001001001);
    std::queue<State> q;
    q.push(mp(V, mp(1*201+1, 0)));
    d[1*201+1][0] = V;
    while(!q.empty()){
        State s = q.front(); q.pop();
        int h = s.first, 
            x = s.second.first / 201, y = s.second.first % 201,
            used = s.second.second;
        // printf("%d, %d, %d\n", h, x, y);
        for(int i=0;i<4;i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(N < nx || nx < 1){continue;}
            if(N < ny || ny < 1){continue;}
            if(h - map[ny][nx] <= 0){continue;}
            if(!used && nx == OX && ny == OY && d[nx*201+ny][1] < (h-map[ny][nx])*2){
                d[nx*201+ny][1] = (h-map[ny][nx]) * 2;
                q.push(mp(d[nx*201+ny][1], mp(nx*201+ny, 1)));
            }
            
            if(d[nx*201+ny][used] < h-map[ny][nx]){
                d[nx*201+ny][used] = h-map[ny][nx];
                q.push(mp(d[nx*201+ny][used], mp(nx*201+ny, used)));
            }
        }
    }
    if(std::max(d[N*201+N][0], d[N*201+N][1]) > 0){
        puts("YES");
    }else{
        puts("NO");
    }
}
            
            
            
        