結果

問題 No.818 Dinner time
ユーザー BwambocosBwambocos
提出日時 2019-04-20 14:44:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 798 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 177,200 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-04-08 16:08:08
合計ジャッジ時間 5,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,676 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 68 ms
20,096 KB
testcase_18 AC 47 ms
14,336 KB
testcase_19 AC 51 ms
14,592 KB
testcase_20 AC 68 ms
18,944 KB
testcase_21 AC 60 ms
16,512 KB
testcase_22 AC 47 ms
13,312 KB
testcase_23 AC 54 ms
14,976 KB
testcase_24 AC 78 ms
20,224 KB
testcase_25 AC 54 ms
14,848 KB
testcase_26 AC 46 ms
12,928 KB
testcase_27 AC 68 ms
18,048 KB
testcase_28 AC 56 ms
15,360 KB
testcase_29 AC 72 ms
19,188 KB
testcase_30 AC 62 ms
16,768 KB
testcase_31 AC 67 ms
17,792 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'LL dp(LL, LL)':
main.cpp:23:27: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
   23 |         return memo[i][j] = res;
main.cpp:19:12: note: 'res' was declared here
   19 |         LL res;
      |            ^~~

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = LLONG_MAX;
LL N, M;
std::vector<LL>A, B;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == -1) return (j == 0 ? -inf : 0);
	if (memo[i][j] != -1) return memo[i][j];
	LL res1 = dp(i - 1, 0);
	LL res2 = dp(i - 1, 1) + B[i];
	LL res3 = dp(i - 1, 2) + std::max({ A[i] * (M - 1) + std::max(A[i], B[i]), B[i] });
	LL res;
	if (j == 0) res = std::max(res1, std::max(res2, res3));
	if (j == 1) res = std::max(res2, res3);
	if (j == 2) res = res3;
	return memo[i][j] = res;
}

int main()
{
	in >> N >> M;
	A.resize(N); B.resize(N);
	rep(i, N) in >> A[i] >> B[i];

	memo.resize(N + 1, std::vector<LL>(5, -1));
	out << dp(N - 1, 0) << std::endl;
}
0