結果

問題 No.861 ケーキカット
ユーザー kotatsugamekotatsugame
提出日時 2020-06-06 13:44:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 631 ms / 1,000 ms
コード長 1,138 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 25,644 KB
最終ジャッジ日時 2023-08-25 00:41:46
合計ジャッジ時間 18,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 624 ms
25,504 KB
testcase_01 AC 631 ms
25,500 KB
testcase_02 AC 622 ms
25,508 KB
testcase_03 AC 621 ms
25,444 KB
testcase_04 AC 622 ms
25,504 KB
testcase_05 AC 619 ms
25,496 KB
testcase_06 AC 622 ms
25,572 KB
testcase_07 AC 623 ms
25,440 KB
testcase_08 AC 607 ms
25,448 KB
testcase_09 AC 624 ms
25,536 KB
testcase_10 AC 618 ms
25,504 KB
testcase_11 AC 622 ms
25,492 KB
testcase_12 AC 624 ms
25,644 KB
testcase_13 AC 624 ms
25,452 KB
testcase_14 AC 613 ms
25,644 KB
testcase_15 AC 616 ms
25,440 KB
testcase_16 AC 615 ms
25,428 KB
testcase_17 AC 623 ms
25,504 KB
testcase_18 AC 623 ms
25,432 KB
testcase_19 AC 629 ms
25,444 KB
testcase_20 AC 619 ms
25,444 KB
testcase_21 AC 623 ms
25,448 KB
testcase_22 AC 628 ms
25,576 KB
testcase_23 AC 623 ms
25,456 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