結果

問題 No.324 落ちてた閉路グラフ
ユーザー snteasntea
提出日時 2015-12-17 14:39:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,695 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 146,412 KB
実行使用メモリ 74,008 KB
最終ジャッジ日時 2023-10-14 12:42:17
合計ジャッジ時間 3,541 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 32 ms
72,508 KB
testcase_05 AC 45 ms
73,936 KB
testcase_06 AC 27 ms
72,304 KB
testcase_07 AC 43 ms
73,764 KB
testcase_08 AC 28 ms
72,368 KB
testcase_09 AC 21 ms
71,816 KB
testcase_10 AC 28 ms
72,404 KB
testcase_11 AC 22 ms
71,824 KB
testcase_12 AC 15 ms
67,424 KB
testcase_13 AC 9 ms
42,612 KB
testcase_14 WA -
testcase_15 AC 11 ms
29,144 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,352 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 26 ms
61,884 KB
testcase_35 AC 2 ms
5,960 KB
testcase_36 AC 14 ms
51,140 KB
testcase_37 AC 2 ms
5,788 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:6: warning: ‘cu’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  int cu;
      ^~

ソースコード

diff #

#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;
}
0