結果

問題 No.1900 Don't be Powers of 2
ユーザー publflpublfl
提出日時 2022-04-08 23:04:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 67,680 KB
実行使用メモリ 51,356 KB
最終ジャッジ日時 2024-05-06 08:47:10
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 20 ms
5,376 KB
testcase_04 AC 21 ms
5,376 KB
testcase_05 AC 20 ms
5,376 KB
testcase_06 AC 21 ms
5,376 KB
testcase_07 AC 20 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 20 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 14 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 10 ms
5,376 KB
testcase_24 AC 14 ms
5,376 KB
testcase_25 AC 14 ms
5,376 KB
testcase_26 AC 106 ms
51,352 KB
testcase_27 AC 37 ms
11,332 KB
testcase_28 AC 20 ms
5,376 KB
testcase_29 AC 19 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 101 ms
51,212 KB
testcase_34 AC 104 ms
51,136 KB
testcase_35 AC 112 ms
51,356 KB
testcase_36 AC 103 ms
48,112 KB
testcase_37 AC 24 ms
5,376 KB
testcase_38 AC 31 ms
17,832 KB
testcase_39 AC 19 ms
8,248 KB
testcase_40 AC 23 ms
5,376 KB
testcase_41 AC 26 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <atcoder/maxflow>

std::vector<int> V[2010];
int color[2010];
void init(int k, int col)
{
	if(color[k]) return;
	color[k] = col;
	for(int i=0;i<V[k].size();i++) init(V[k][i],3-col);
}

std::vector< std::pair<int,int> > edge;
int x[2010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	
	for(int i=1;i<=a;i++)
	{
		for(int j=i+1;j<=a;j++)
		{
			int val = (x[i]^x[j]);
			
			if(val%65536==0) val/=65536;
			if(val%256==0) val/=256;
			if(val%16==0) val/=16;
			if(val%4==0) val/=4;
			if(val%2==0) val/=2;
			
			if(val==1)
			{
				V[i].push_back(j);
				V[j].push_back(i);
				edge.push_back(std::make_pair(i,j));
			}
		}
	}
	for(int i=1;i<=a;i++) init(i,1);
	
	atcoder::mf_graph<int> G(2*a+3);
	int source = 2*a+1, sink = 2*a+2;
	
	for(int i=1;i<=a;i++) G.add_edge(source,i,1);
	for(int i=1;i<=a;i++) G.add_edge(i+a,sink,1);
	
	for(int i=0;i<edge.size();i++)
	{
		int s = edge[i].first, t = edge[i].second;
		if(color[s]==2)
		{
			int temp = s;
			s = t;
			t = temp;
		}
		G.add_edge(s,a+t,1);
	}
	
	printf("%d",a-G.flow(source,sink));
}
0