結果

問題 No.974 最後の日までに
ユーザー kotatsugamekotatsugame
提出日時 2020-01-18 00:35:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 1,063 ms
コンパイル使用メモリ 85,244 KB
実行使用メモリ 13,520 KB
最終ジャッジ日時 2024-04-14 21:52:36
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
12,296 KB
testcase_01 AC 65 ms
12,280 KB
testcase_02 AC 65 ms
11,976 KB
testcase_03 AC 66 ms
11,728 KB
testcase_04 AC 65 ms
12,388 KB
testcase_05 AC 54 ms
12,076 KB
testcase_06 AC 54 ms
12,432 KB
testcase_07 AC 54 ms
12,784 KB
testcase_08 AC 55 ms
13,520 KB
testcase_09 AC 55 ms
12,236 KB
testcase_10 AC 55 ms
12,392 KB
testcase_11 AC 56 ms
12,452 KB
testcase_12 AC 56 ms
11,888 KB
testcase_13 AC 60 ms
13,104 KB
testcase_14 AC 58 ms
11,716 KB
testcase_15 AC 63 ms
12,060 KB
testcase_16 AC 64 ms
13,380 KB
testcase_17 AC 62 ms
13,388 KB
testcase_18 AC 61 ms
12,404 KB
testcase_19 AC 60 ms
12,064 KB
testcase_20 AC 61 ms
13,056 KB
testcase_21 AC 61 ms
12,564 KB
testcase_22 AC 61 ms
11,832 KB
testcase_23 AC 61 ms
12,056 KB
testcase_24 AC 60 ms
11,800 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 44 ms
13,132 KB
testcase_28 AC 57 ms
12,272 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 64 ms
11,652 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 38 ms
8,016 KB
testcase_34 AC 60 ms
11,804 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 66 ms
12,040 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 40 ms
12,564 KB
testcase_41 AC 52 ms
12,124 KB
testcase_42 AC 67 ms
12,052 KB
testcase_43 AC 65 ms
12,392 KB
testcase_44 AC 49 ms
12,564 KB
testcase_45 AC 41 ms
8,400 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int W;
long A[55],B[55],C[55];
vector<pair<long,long> >X;
void dfs(int d,int lim,long x,long y)
{
	if(d==lim)
	{
		X.push_back(make_pair(y,x));
		return;
	}
	dfs(d+1,lim,x,y+A[d]);
	if(d+2<=lim)dfs(d+2,lim,x+B[d+1],y-C[d+1]);
}
main()
{
	cin>>W;
	for(int i=0;i<W;i++)cin>>A[i]>>B[i]>>C[i];
	if(W==1)
	{
		cout<<0<<endl;
		return 0;
	}
	long ans=0;
	for(int mid:(vector<int>){W/2-1,W/2})
	{
		dfs(0,mid,0,0);
		sort(X.rbegin(),X.rend());
		vector<pair<long,long> >A;
		long pre=-1;
		for(pair<long,long>p:X)
		{
			if(pre<p.second)
			{
				pre=p.second;
				A.push_back(p);
			}
		}
		sort(A.begin(),A.end());
		X.clear();
		dfs(mid,W,0,0);
		for(pair<long,long>p:X)
		{
			vector<pair<long,long> >::iterator it=lower_bound(A.begin(),A.end(),make_pair(-p.first,0L));
			if(it!=A.end())ans=max(ans,p.second+it->second);
		}
		X.clear();
	}
	cout<<ans<<endl;
}
0