結果
問題 | No.2982 Logic Battle |
ユーザー |
![]() |
提出日時 | 2024-12-09 14:25:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,046 bytes |
コンパイル時間 | 470 ms |
コンパイル使用メモリ | 42,752 KB |
最終ジャッジ日時 | 2025-02-26 11:41:36 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:37:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | for (int j = 0; j < 3; j++) scanf("%d", as[i] + j); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2982.cc: No.2982 Logic Battle - yukicoder*/#include<cstdio>#include<algorithm>#include<utility>using namespace std;/* constant */const int MAX_N = 5000;/* typedef */using ll = long long;using pll = pair<ll,ll>;/* global variables */int as[MAX_N][3];pll dp[MAX_N + 1][3];/* subroutines */template <typename T>inline void setmax(T &a, T b) { if (a < b) a = b; }/* main */int main() {int n;scanf("%d", &n);for (int i = 0; i < n; i++)for (int j = 0; j < 3; j++) scanf("%d", as[i] + j);for (int i = 0; i < n; i++)for (int j = 0; j < 3; j++) {int j1 = (j + 1) % 3, j2 = (j + 2) % 3;auto [s1, x1] = dp[i][j1];auto [s2, x2] = dp[i][j2];ll d1 = s1 + x1 + as[i][j], d2 = s2 + x2 + as[i][j];if (d1 >= d2) dp[i + 1][j] = {d1, max(0LL, x1 + as[i][j] - 1)};else dp[i + 1][j] = {d2, max(0LL, x2 + as[i][j] - 1)};}ll maxd = max(dp[n][0].first, max(dp[n][1].first, dp[n][2].first));printf("%lld\n", maxd);return 0;}