結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー ronnyaronnya
提出日時 2022-05-20 23:34:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,515 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 215,728 KB
実行使用メモリ 15,564 KB
最終ジャッジ日時 2023-10-20 14:30:07
合計ジャッジ時間 4,303 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 65 ms
7,752 KB
testcase_08 WA -
testcase_09 AC 75 ms
7,300 KB
testcase_10 AC 80 ms
7,780 KB
testcase_11 AC 80 ms
7,816 KB
testcase_12 AC 74 ms
7,832 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 75 ms
15,564 KB
testcase_16 AC 20 ms
7,300 KB
testcase_17 AC 129 ms
12,672 KB
testcase_18 AC 20 ms
7,300 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 71 ms
10,880 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 62 ms
7,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

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

  set<pair<ll, pair<ll, ll>>> st;
  st.insert({0, {x, y}});


  while(!st.empty()){
    auto s = *st.begin();
    st.erase(s);
    if(atk < s.first) break;
    else{
      atk += s.first;
    }

    ll posx = s.second.first;
    ll posy = s.second.second;
    if(posx == h - 1 && posy == w - 1){
      f = 1;
      break;
    }
    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;
        st.insert({a[nx][ny], {nx, ny}});
      }
    }

  }

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



  return 0;
}
0