結果
| 問題 | No.698 ペアでチームを作ろう |
| ユーザー |
siman
|
| 提出日時 | 2021-05-10 16:43:13 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 1,000 ms |
| コード長 | 883 bytes |
| 記録 | |
| コンパイル時間 | 3,618 ms |
| コンパイル使用メモリ | 147,840 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-04-08 09:25:07 |
| 合計ジャッジ時間 | 5,731 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp:19:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
19 | int A[N];
| ^
main.cpp:19:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N;
| ^
main.cpp:25:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
25 | int dp[1 << N];
| ^~~~~~
main.cpp:25:15: note: read of non-const variable 'N' is not allowed in a constant expression
25 | int dp[1 << N];
| ^
main.cpp:17:7: note: declared here
17 | int N;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
int A[N];
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
int dp[1 << N];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < N / 2; ++i) {
for (int mask = 0; mask < (1 << N); ++mask) {
if (__builtin_popcount(mask) != 2 * i) continue;
for (int s = 0; s < N; ++s) {
if (mask >> s & 1) continue;
for (int t = 0; t < N; ++t) {
if (mask >> t & 1) continue;
int nmask = mask | (1 << s) | (1 << t);
dp[nmask] = max(dp[nmask], dp[mask] + (A[s] ^ A[t]));
}
}
}
}
cout << dp[(1 << N) - 1] << endl;
return 0;
}
siman