結果

問題 No.1900 Don't be Powers of 2
ユーザー 37zigen37zigen
提出日時 2022-02-25 00:53:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 91,896 KB
実行使用メモリ 35,500 KB
最終ジャッジ日時 2024-05-06 00:49:48
合計ジャッジ時間 8,865 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 312 ms
5,376 KB
testcase_04 AC 306 ms
5,376 KB
testcase_05 AC 317 ms
5,376 KB
testcase_06 AC 311 ms
5,376 KB
testcase_07 AC 309 ms
5,376 KB
testcase_08 AC 46 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 65 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 208 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 7 ms
5,376 KB
testcase_17 AC 283 ms
5,376 KB
testcase_18 AC 233 ms
5,376 KB
testcase_19 AC 307 ms
5,376 KB
testcase_20 AC 215 ms
5,376 KB
testcase_21 AC 204 ms
5,376 KB
testcase_22 AC 195 ms
5,376 KB
testcase_23 AC 180 ms
5,376 KB
testcase_24 AC 180 ms
5,376 KB
testcase_25 AC 216 ms
5,376 KB
testcase_26 AC 311 ms
35,372 KB
testcase_27 AC 89 ms
8,892 KB
testcase_28 AC 86 ms
5,376 KB
testcase_29 AC 81 ms
5,376 KB
testcase_30 AC 7 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 316 ms
35,500 KB
testcase_34 AC 316 ms
35,372 KB
testcase_35 AC 306 ms
35,372 KB
testcase_36 AC 317 ms
33,712 KB
testcase_37 AC 117 ms
5,376 KB
testcase_38 AC 48 ms
13,392 KB
testcase_39 AC 36 ms
6,896 KB
testcase_40 AC 306 ms
5,376 KB
testcase_41 AC 306 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 <atcoder/maxflow>
#include <iostream>

using namespace std;
using namespace atcoder;

int popcount(int a) {
	if (a == 0) return 0;
	return popcount(a / 2) + a % 2;
}

int main() {
    int n;
    cin >> n;
	assert(1 <= n && n <= 2000);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
    	cin >> a[i];
    	assert(0 <= a[i] && a[i] < 1 << 30);
    }
    
    mf_graph<int> g(n + 2);
    int s = n;
	int t = n + 1;

    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < n; ++j) {
    		if (popcount(a[i]) % 2 == 0 && popcount(a[j]) % 2 == 1 && popcount(a[i] ^ a[j]) ==1) {
    			g.add_edge(i, j, 1);	
    		}
    	}
    }
	
	for (int i = 0; i < n; ++i) if (popcount(a[i]) % 2 == 0) g.add_edge(s, i, 1);
	for (int i = 0; i < n; ++i) if (popcount(a[i]) % 2 == 1) g.add_edge(i, t, 1);

	cout << n-g.flow(s, t) << endl;
    return 0;
}
0