結果

問題 No.1948 足し算するだけのパズルゲーム(1)
ユーザー MasKoaTSMasKoaTS
提出日時 2022-05-20 23:17:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,885 bytes
コンパイル時間 4,721 ms
コンパイル使用メモリ 273,888 KB
実行使用メモリ 23,680 KB
最終ジャッジ日時 2023-10-20 14:10:45
合計ジャッジ時間 11,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 115 ms
19,536 KB
testcase_08 AC 130 ms
18,984 KB
testcase_09 AC 170 ms
19,536 KB
testcase_10 AC 209 ms
19,536 KB
testcase_11 AC 155 ms
19,372 KB
testcase_12 AC 287 ms
19,472 KB
testcase_13 AC 635 ms
19,472 KB
testcase_14 AC 280 ms
19,480 KB
testcase_15 AC 106 ms
19,456 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define print(n) cout << (n) << endl
#define fprint(n) cout << setprecision(16) << (n) << endl
#define ceil_div(a, b) (((a) - 1) / (b) + 1)
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++)
#define ite(i, a) for (auto& i : a)
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
#define lbi(A, x) (ll)(lb(all(A), x) - A.begin())
#define ubi(A, x) (ll)(ub(all(A), x) - A.begin())
using str = string;
using ll = long long;
using Pair = pair<int, int>;
using mint = modint1000000007;
using Mint = modint998244353;
template <class T>	using V = vector<T>;
template <class T>	using VV = V<V<T> >;
template <class T>	using PQ = priority_queue<T, V<T>, greater<T> >;
template <class T>	using PQR = priority_queue<T>;
template <class T>	using BIT = fenwick_tree<T>;
const ll INF = 4611686018427387903;
const int inf = 2147483647;
const ll mod = 1000000007;
const ll MOD = 998244353;
template <class T>  inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; }
template <class T>  inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; }
template <class T> inline void prints(V<T>& vec) { if (vec.size() == 0)return; cout << vec[0];	rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; }
inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; }
inline V<int> atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; }
inline V<int> Atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; }


int main(void) {
	int h, w;	cin >> h >> w;
	VV<ll> a = getGrid<ll>(h, w);

	VV<V<ll> > dp(h, VV<ll>(w, V<ll>(2)));
	dp[0][0][0] = a[0][0];
	deque<V<ll> > que = { {0,0,a[0][0],0} };
	int m = 0;
	while (que.empty() == false) {
		ll x = que[0][0], y = que[0][1], t = que[0][2], c = que[0][3];
		que.pop_front();
		V<ll> dx = { 1,0 }, dy = { 0,1 };
		rep(i, 0, 2) {
			ll nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 or nx >= h or ny < 0 or ny >= w) {
				continue;
			}
			if (t > a[nx][ny] and t + a[nx][ny] > dp[nx][ny][c]) {
				dp[nx][ny][c] = t + a[nx][ny];
				if (nx + ny >= m) {
					que.push_back({ nx, ny, t + a[nx][ny], c });
					m++;
				}
				else {
					que.push_front({ nx, ny, t + a[nx][ny], c });
				}
			}
			else if (c == 0 and (nx != h - 1 or ny != w - 1) and t > dp[nx][ny][1]) {
				dp[nx][ny][1] = t;
				if (nx + ny >= m) {
					que.push_back({ nx, ny, t, 1 });
					m++;
				}
				else {
					que.push_front({ nx, ny, t, 1 });
				}
			}
		}
	}
	
	if (dp[h - 1][w - 1][0] + dp[h - 1][w - 1][1] > 0) {
		print("Yes");
	}
	else {
		print("No");
	}

	return 0;
}
0