結果

問題 No.3822 Permuted Pairwise XOR
コンテスト
ユーザー tnakao0123
提出日時 2026-11-24 14:33:14
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 24 ms / 2,000 ms
+ 83µs
コード長 1,270 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 235 ms
コンパイル使用メモリ 61,392 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-24 14:33:17
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/algorithm:62,
                 from main.cpp:7:
In function 'void std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]',
    inlined from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:979:21,
    inlined from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int*; _Tp = int]' at /home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:1011:20,
    inlined from 'int main()' at main.cpp:39:7:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/bits/stl_algobase.h:925:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' specified size between 18446744065119617020 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
  925 |         *__first = __val;
      |         ~~~~~~~~~^~~~~~~
main.cpp: In function 'int main()':
main.cpp:20:39: note: destination object allocated here
   20 | int ds[MAX_N], bs[MAX_N], xds[MAX_N], xbs[MAX_N];
      |                                       ^~~

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3822.cc:  No.3822 Permuted Pairwise XOR - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 300;

/* typedef */

/* global variables */

int as[MAX_N];
int ds[MAX_N], bs[MAX_N], xds[MAX_N], xbs[MAX_N];
bool used[MAX_N];

/* subroutines */

int cmpv(int n, int v0[], int v1[]) {
  for (int i = 0; i < n; i++)
    if (v0[i] != v1[i]) return (v0[i] < v1[i]) ? -1 : 1;
  return 0;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  fill(xds, xds + n, -1);
  fill(xbs, xbs + n - 1, -1);

  for (int i = 0; i < n; i++) {
    fill(used, used + n, false);
    used[i] = true;
    ds[0] = as[i];
    for (int j = 1; j < n; j++) {
      int maxb = -1, maxk = -1;
      for (int k = 0; k < n; k++)
	if (! used[k]) {
	  int b = ds[j - 1] ^ as[k];
	  if (maxb < b) maxb = b, maxk = k;
	}
      bs[j - 1] = maxb;
      ds[j] = as[maxk];
      used[maxk] = true;
    }

    int c0 = cmpv(n - 1, xbs, bs);
    if (c0 < 0 || (c0 == 0 && cmpv(n, xds, ds) < 0)) {
      copy(bs, bs + (n - 1), xbs);
      copy(ds, ds + n, xds);
    }
  }

  for (int i = 0; i < n; i++)
    printf("%d%c", xds[i], (i + 1 < n) ? ' ' : '\n');
  
  return 0;
}
0