結果

問題 No.324 落ちてた閉路グラフ
ユーザー yuppe19 😺
提出日時 2015-12-17 00:52:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,715 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 52,380 KB
最終ジャッジ日時 2024-11-14 19:31:10
合計ジャッジ時間 1,095 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:11:1: error: ‘vector’ does not name a type
   11 | vector<int> w;
      | ^~~~~~
main.cpp: In function ‘int rec(int, int, bool, bool)’:
main.cpp:22:37: error: ‘w’ was not declared in this scope
   22 |       return res = (before&&first ? w[i-1] : 0);
      |                                     ^
main.cpp:32:61: error: ‘w’ was not declared in this scope
   32 |     if(j < m) { res = max(res, rec(i+1, j+1, true, first) + w[i-1]); }
      |                                                             ^
main.cpp: In function ‘int main()’:
main.cpp:47:3: error: ‘w’ was not declared in this scope
   47 |   w.assign(n, 0);
      |   ^
main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
const int inf = 987654321;
int n, m;
vector<int> w;
//vector<vector<vector<vector<int>>>> dp;
int dp[2][2][3005][3005];
// ijbefore: ? first: ?
//
int rec(int i, int j, bool before, bool first) {
// int &res = dp[i][j][before][first];
int &res = dp[before][first][i][j];
if(i==n) {
if(j==m) {
return res = (before&&first ? w[i-1] : 0);
} else {
return res = -inf;
}
}
if(res != -1) { return res; }
res = -inf;
//
if(before) {
// i
if(j < m) { res = max(res, rec(i+1, j+1, true, first) + w[i-1]); }
//
res = max(res, rec(i+1, j, false, first));
//
} else {
// i
if(j < m) { res = max(res, rec(i+1, j+1, true, first)); }
//
res = max(res, rec(i+1, j, false, first));
}
return res;
}
int main(void) {
scanf("%d%d", &n, &m);
w.assign(n, 0);
for(int i : range(3005)) for(int j : range(3005)) for(int k : range(2)) for(int L : range(2)) dp[k][L][i][j] = -1;
// dp.assign(n+10, vector<vector<vector<int>>>(m+10, vector<vector<int>>(2, vector<int>(2, -1))));
for(int i : range(n)) { scanf("%d", &w[i]); }
int res = max(rec(1, 1, 1, 1), rec(1, 0, 0, 0));
printf("%d\n", res);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0