結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ronnya
提出日時 2022-05-20 23:43:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 3,000 ms
コード長 1,527 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 205,356 KB
最終ジャッジ日時 2025-01-29 11:58:49
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

using pp = pair<ll, pair<ll, ll>>;

#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
#define irep(i, v) for(auto i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()


const ll INF = 1e18;
const ld EPS = 1e-10;
const ll MOD = 1e9 + 7;
const ld PI = M_PI;

vector<ll> dx = {0, 0, 1, -1};
vector<ll> dy = {1, -1, 0, 0};

ll h, w;

bool in_grid(ll x, ll y){
  return (0 <= x && x < h && 0 <= y && y < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  cout << fixed << setprecision(20);

  ll x, y;
  cin >> h >> w >> x >> y;
  x--; y--;
  vector<vector<ll>> a(h, vector<ll>(w));
  rep(i, 0, h) rep(j, 0, w) cin >> a[i][j];

  ll atk = a[x][y];
  a[x][y] = 0;
  vector<vector<ll>> seen(h, vector<ll>(w, 0));
  bool f = 0;

  seen[x][y] = 1;

  priority_queue< pp, vector< pp >, greater< pp >> que; 
  que.push({0, {x, y}});


  while(!que.empty()){
    auto s = que.top();
    que.pop();
    if(atk <= s.first){
      f = 1;
      break;
    }
    else{
      atk += s.first;
    }

    ll posx = s.second.first;
    ll posy = s.second.second;


    rep(k, 0, 4){
      ll nx = posx + dx[k];
      ll ny = posy + dy[k];
      if(in_grid(nx, ny) && seen[nx][ny] == 0){
        seen[nx][ny] = 1;
        que.push({a[nx][ny], {nx, ny}});
      }
    }

  }

  if(!f) cout << "Yes" << endl;
  else cout << "No" << endl;



  return 0;
}
0