結果
問題 |
No.698 ペアでチームを作ろう
|
ユーザー |
![]() |
提出日時 | 2018-06-18 18:42:06 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 1,299 bytes |
コンパイル時間 | 930 ms |
コンパイル使用メモリ | 83,928 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-30 17:00:33 |
合計ジャッジ時間 | 1,449 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:48:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | for (int i = 0; i < n; i++) scanf("%d", &as[i]); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 698.cc: No.698 ペアでチームを作ろう - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 14; const int NBITS = 1 << MAX_N; /* typedef */ /* global variables */ int as[MAX_N], dp[NBITS], bnums[NBITS]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &as[i]); int nbits = 1 << n; bnums[0] = 0; for (int bits = 1, msb = 1; bits < nbits; bits++) { if ((msb << 1) <= bits) msb <<= 1; bnums[bits] = bnums[bits ^ msb] + 1; } for (int bits = 0, msb = 1; bits < nbits; bits++) { if (bnums[bits] & 1) continue; for (int i = 0, bi = 1; i < n; i++, bi <<= 1) if (! (bits & bi)) for (int j = i + 1, bj = 1 << (i + 1); j < n; j++, bj <<= 1) if (! (bits & bj)) setmax(dp[bits | bi | bj], dp[bits] + (as[i] ^ as[j])); } printf("%d\n", dp[nbits - 1]); return 0; }