結果

問題 No.861 ケーキカット
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 19:31:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 639 ms / 1,000 ms
コード長 1,138 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 77,072 KB
実行使用メモリ 25,624 KB
最終ジャッジ日時 2023-09-22 02:23:07
合計ジャッジ時間 17,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 624 ms
25,436 KB
testcase_01 AC 620 ms
25,328 KB
testcase_02 AC 635 ms
25,624 KB
testcase_03 AC 628 ms
25,320 KB
testcase_04 AC 629 ms
25,324 KB
testcase_05 AC 629 ms
25,324 KB
testcase_06 AC 611 ms
25,324 KB
testcase_07 AC 609 ms
25,624 KB
testcase_08 AC 605 ms
25,372 KB
testcase_09 AC 603 ms
25,452 KB
testcase_10 AC 597 ms
25,468 KB
testcase_11 AC 617 ms
25,468 KB
testcase_12 AC 626 ms
25,500 KB
testcase_13 AC 638 ms
25,568 KB
testcase_14 AC 634 ms
25,452 KB
testcase_15 AC 635 ms
25,372 KB
testcase_16 AC 636 ms
25,384 KB
testcase_17 AC 636 ms
25,320 KB
testcase_18 AC 639 ms
25,544 KB
testcase_19 AC 636 ms
25,568 KB
testcase_20 AC 633 ms
25,436 KB
testcase_21 AC 622 ms
25,384 KB
testcase_22 AC 626 ms
25,476 KB
testcase_23 AC 626 ms
25,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:64:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   64 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
struct precalc{
	bool ok[1<<25];
	precalc()
	{
		queue<int>P;
		ok[0]=true;
		for(int i=0;i<25;i++)
		{
			ok[1<<i]=true;
			P.push(1<<i);
		}
		while(!P.empty())
		{
			int u=P.front();P.pop();
			for(int i=0;i<25;i++)
			{
				if(!(u>>i&1))continue;
				if(i>=5&&!(u>>i-5&1))
				{
					int v=u|1<<i-5;
					if(!ok[v])
					{
						ok[v]=true;
						P.push(v);
					}
				}
				if(i<20&&!(u>>i+5&1))
				{
					int v=u|1<<i+5;
					if(!ok[v])
					{
						ok[v]=true;
						P.push(v);
					}
				}
				if(i%5>0&&!(u>>i-1&1))
				{
					int v=u|1<<i-1;
					if(!ok[v])
					{
						ok[v]=true;
						P.push(v);
					}
				}
				if(i%5<4&&!(u>>i+1&1))
				{
					int v=u|1<<i+1;
					if(!ok[v])
					{
						ok[v]=true;
						P.push(v);
					}
				}
			}
		}
	}
};
precalc OK;
long C[25];
main()
{
	long all=0;
	for(int i=0;i<25;i++)
	{
		cin>>C[i];
		all+=C[i];
	}
	long ans=all;
	for(int i=0;i<1<<25;i++)
	{
		if(OK.ok[i]&&OK.ok[(1<<25)-1^i])
		{
			long t=0;
			for(int j=0;j<25;j++)if(i>>j&1)t+=C[j];
			ans=min(ans,abs(all-t*2));
		}
	}
	cout<<ans<<endl;
}
0