結果
問題 |
No.324 落ちてた閉路グラフ
|
ユーザー |
![]() |
提出日時 | 2015-12-17 14:39:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,695 bytes |
コンパイル時間 | 1,269 ms |
コンパイル使用メモリ | 159,936 KB |
実行使用メモリ | 73,856 KB |
最終ジャッジ日時 | 2024-09-16 07:31:49 |
合計ジャッジ時間 | 2,910 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 25 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:41:13: warning: ‘cu’ may be used uninitialized in this function [-Wmaybe-uninitialized] 41 | int cu; | ^~
ソースコード
#include <bits/stdc++.h> #include <cmath> #include <climits> #include <cstdio> using namespace std; #define endl '\n' #define PB push_back #define ALL(a) (a).begin(),(a).end() #define SZ(a) int((a).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define AALL(a,n) (a),(a)+(n) typedef pair<int,int> P; typedef long long int LL; typedef unsigned long long ULL; typedef pair<LL,LL> LP; int dp[3000+5][3000+5][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; vector<int> w(n); int ans = 0; if(m == n){ REP(i,n) ans = w[i]; cout << ans << endl; return 0; } REP(i,n) cin >> w[i]; int tmp = INT_MAX; int cu; REP(i,n){ if(tmp > w[i]+w[(i+1)%n]){ cu = i; tmp = w[i]+w[(i+1)%n]; } } //DEBUG(cu); FOR(i,1,n){ dp[0][i][0] = dp[0][i][1] = INT_MIN; } REP(i,n){ dp[i][0][1] = INT_MIN; } FOR(j,1,m+1){ int i = 1; dp[i][j][0] = max(dp[i-1][j][0],dp[i-1][j][1]); dp[i][j][1] = max(dp[i-1][j-1][0],(dp[i-1][j-1][1] == INT_MIN)?INT_MIN:(dp[i-1][j-1][1])); } FOR(i,2,n){ FOR(j,1,m+1){ dp[i][j][0] = max(dp[i-1][j][0],dp[i-1][j][1]); dp[i][j][1] = max(dp[i-1][j-1][0],(dp[i-1][j-1][1] == INT_MIN)?INT_MIN:(dp[i-1][j-1][1]+w[(cu+i)%n])); //DEBUG(w[(cu+i)%n]); } } /*cout << endl; REP(i,n){ REP(j,m+1){ cout << dp[i][j][0] << ' '; } cout << endl; } cout << endl; REP(i,n){ REP(j,m+1){ cout << dp[i][j][1] << ' '; } cout << endl; } cout << endl;*/ ans = max({dp[n-1][m][0],dp[n-1][m][1]}); cout << ans << endl; return 0; }