結果

問題 No.844 split game
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-06-28 22:09:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 198,728 KB
最終ジャッジ日時 2025-01-07 05:32:43
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:31: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
   15 |                 scanf("%d%d%lld", &l, &r, &p);
      |                            ~~~^           ~~
      |                               |           |
      |                               |           int64_t* {aka long int*}
      |                               long long int*
      |                            %ld
main.cpp:35:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type’ {aka ‘long int’} [-Wformat=]
   35 |         printf("%lld\n", maxDP.back());
      |                 ~~~^     ~~~~~~~~~~~~
      |                    |               |
      |                    long long int   __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type {aka long int}
      |                 %ld
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d%d%d", &N, &M, &A);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |                 scanf("%d%d%lld", &l, &r, &p);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

int main()
{
	int N, M, A;
	scanf("%d%d%d", &N, &M, &A);
	using vpi = std::vector<std::pair<int, int64_t>>;
	using vvpi = std::vector<vpi>;

	vvpi spans(N + 1);
	for (int i{}; i < M; i++)
	{
		int l, r;
		int64_t p;
		scanf("%d%d%lld", &l, &r, &p);
		spans[r].push_back({l, p});
	}
	std::vector<int64_t> dp(N + 1, -(1ll << 60));
	std::vector<int64_t> maxDP(N + 1);
	dp[0] = 0;
	for (int i{1}; i <= N; i++)
	{
		for (auto& e: spans[i])
		{
			int64_t last_bonus{};
			if (i == N) last_bonus += A;
			if (dp[e.first - 1] != -(1ll << 60))
				dp[i] = std::max(dp[i], dp[e.first - 1] + e.second - A + last_bonus);
				
			if (e.first > 1)
				dp[i] = std::max(dp[i], maxDP[e.first - 2] + e.second - 2 * A + last_bonus);
		}
		maxDP[i] = std::max({maxDP[i - 1], dp[i]});
	}
	printf("%lld\n", maxDP.back());

	return 0;
}
0