結果

問題 No.1949 足し算するだけのパズルゲーム(2)
ユーザー shinchanshinchan
提出日時 2022-05-20 22:31:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 3,000 ms
コード長 1,712 bytes
コンパイル時間 2,351 ms
コンパイル使用メモリ 217,240 KB
実行使用メモリ 14,480 KB
最終ジャッジ日時 2023-10-20 13:15:41
合計ジャッジ時間 4,320 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 53 ms
6,664 KB
testcase_08 AC 32 ms
6,144 KB
testcase_09 AC 60 ms
6,144 KB
testcase_10 AC 64 ms
6,696 KB
testcase_11 AC 64 ms
6,732 KB
testcase_12 AC 57 ms
6,748 KB
testcase_13 AC 48 ms
6,712 KB
testcase_14 AC 67 ms
14,480 KB
testcase_15 AC 65 ms
14,480 KB
testcase_16 AC 18 ms
6,144 KB
testcase_17 AC 89 ms
11,576 KB
testcase_18 AC 19 ms
6,144 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 58 ms
9,844 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 35 ms
6,696 KB
testcase_25 AC 51 ms
6,492 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:57:13: warning: 'now' may be used uninitialized [-Wmaybe-uninitialized]
   57 |         now += d;
      |         ~~~~^~~~
main.cpp:17:8: note: 'now' was declared here
   17 |     ll now;
      |        ^~~

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false); 
    ll h, w, y, x;
    cin >> h >> w >> y >> x;
    ll now;
    y--; x--;
    vector a(h, vector(w, 0LL));
    multiset<tuple<ll, int, int>> ms;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if(i == y && j == x) {
            now = a[i][j];
        }
    }

    // cout << "aa" << endl;

    vector seen(h, vector(w, 0));
    seen[y][x] = 1;
    int dy[4] = {-1, 0, 0, 1};
    int dx[4] = {0, -1, 1, 0};
    rep(k, 4) {
        // cout << k << endl;
        int i = dy[k] + y;
        int j = dx[k] + x;
        if(i < 0 || i > h - 1 || j < 0 || j > w - 1) continue;
        if(seen[i][j]) continue;
        seen[i][j] = 1;
        ms.insert({a[i][j], i, j});
    }


    // cout << "aa" << endl;


    while(!ms.empty()) {
        // cout << "Jj" << endl;
        auto [d, ii, jj] = *ms.begin();
        ms.erase(ms.begin());
        // cout << ii << " " << jj << " " << d << " " << now << endl;
        if(d >= now) {
            cout << "No" << endl;
            return 0;
        }
        now += d;
        rep(k, 4) {
            int i = ii + dy[k];
            int j = jj + dx[k];
            if(i < 0 || i >= h || j < 0 || j >= w) continue;
            if(seen[i][j]) continue;
            seen[i][j] = 1;
            ms.insert({a[i][j], i, j});
        }
    }
    cout << "Yes" << endl;
    return 0;
}
0