結果
| 問題 |
No.2889 Rusk
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-10-04 00:47:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 2,000 ms |
| コード長 | 1,279 bytes |
| コンパイル時間 | 1,865 ms |
| コンパイル使用メモリ | 194,600 KB |
| 実行使用メモリ | 27,220 KB |
| 最終ジャッジ日時 | 2025-10-04 00:47:50 |
| 合計ジャッジ時間 | 8,762 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
main.cpp:14:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:15:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(int i = 1; i <= n; ++i) scanf("%lld", &b[i]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:16:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | for(int i = 1; i <= n; ++i) scanf("%lld", &c[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5 + 10;
int n;
int a[MAXN], b[MAXN], c[MAXN];
int f[MAXN][6], g[MAXN][6];
int ans = 0;
signed main() {
scanf("%lld", &n);
for(int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
for(int i = 1; i <= n; ++i) scanf("%lld", &b[i]);
for(int i = 1; i <= n; ++i) scanf("%lld", &c[i]);
for(int i = 1; i <= n; ++i) ans = ans + a[i];
memset(f, -0x3f, sizeof f);
memset(g, -0x3f, sizeof g);
f[0][1] = g[0][1] = 0;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= 5; ++j) {
f[i][j] = max(f[i - 1][j], f[i - 1][j - 1]) + ((j & 1) ? a[i] : b[i]);
}
}
for(int j = 1; j <= 5; ++j) {
// cout << "view: " << j << " " << f[n][j] << "\n";
ans = max(ans, f[n][j]);
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= 5; ++j) {
int val;
if(j == 1 || j == 5) val = a[i];
else if(j == 2 || j == 4) val = b[i];
else val = c[i];
for(int k = 1; k <= j; ++k) {
g[i][j] = max(g[i][j], g[i - 1][k] + val);
}
}
}
for(int j = 1; j <= 5; ++j) ans = max(ans, g[n][j]);
printf("%lld\n", ans);
return 0;
}
/*
?? b,c ?????????????????????
???????
??????? 0..01..10..01..10..0 ? 0..01..12..21..10..0 ?????
????????? b ??????????? max ??? max??????
??????? 5 ??? DP ???
*/
vjudge1