結果

問題 No.818 Dinner time
ユーザー Bwambocos
提出日時 2019-04-19 23:13:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 177,404 KB
実行使用メモリ 23,168 KB
最終ジャッジ日時 2024-09-23 04:21:35
合計ジャッジ時間 3,855 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'LL dp(LL, LL)':
main.cpp:25:27: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
   25 |         return memo[i][j] = res;
main.cpp:21:12: note: 'res' was declared here
   21 |         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) + std::max(A[i], B[i]);
	LL res4 = 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 res5 = dp(i - 1, 2) + std::max({ A[i] * (M - 1) + std::max(A[i], B[i]) });
	LL res;
	if (j == 0) res = std::max(res1, std::max(res4, res5));
	if (j == 1) res = std::max(res2, res5);
	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