結果

問題 No.3822 Permuted Pairwise XOR
コンテスト
ユーザー テナガザル
提出日時 2026-11-22 13:21:37
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 11 ms / 2,000 ms
+ 632µs
コード長 980 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,314 ms
コンパイル使用メモリ 185,032 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-11-22 13:21:40
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> ansb(n - 1, -1), ans(n, -1);
  int ma = -1, id = -1;
  for (int i = 0; i < n; ++i)
  {
    auto b = a;
    vector<int> tmp;
    tmp.push_back(b[i]);
    b.erase(b.begin() + i);
    while (!b.empty())
    {
      int ma = -1, id = -1;
      for (int j = 0; j < b.size(); ++j)
      {
        int tv = tmp.back() ^ b[j];
        if (tv >= ma)
        {
          ma = tv;
          id = j;
        }
      }
      tmp.push_back(b[id]);
      b.erase(b.begin() + id);
    }
    vector<int> tmpb(n - 1);
    for (int i = 0; i < n - 1; ++i) tmpb[i] = tmp[i] ^ tmp[i + 1];
    if (ansb < tmpb)
    {
      ansb = tmpb;
      ans = tmp;
    }
    else if (ansb == tmpb && ans < tmp) ans = tmp;
  }
  for (int i = 0; i < n; ++i) cout << ans[i] << " \n"[i == n - 1];
}
0