結果

問題 No.2732 Similar Permutations
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-04-19 21:50:13
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 2,711 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 134,488 KB
実行使用メモリ 13,232 KB
最終ジャッジ日時 2024-04-19 21:50:36
合計ジャッジ時間 22,554 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 62 ms
5,376 KB
testcase_03 AC 110 ms
7,220 KB
testcase_04 AC 34 ms
5,376 KB
testcase_05 AC 26 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 81 ms
6,036 KB
testcase_08 AC 39 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 AC 195 ms
13,232 KB
testcase_11 AC 15 ms
5,376 KB
testcase_12 AC 196 ms
12,132 KB
testcase_13 AC 194 ms
12,132 KB
testcase_14 AC 205 ms
11,876 KB
testcase_15 AC 197 ms
12,116 KB
testcase_16 AC 142 ms
8,744 KB
testcase_17 AC 142 ms
8,572 KB
testcase_18 AC 179 ms
12,992 KB
testcase_19 AC 192 ms
12,132 KB
testcase_20 AC 196 ms
11,980 KB
testcase_21 AC 197 ms
12,136 KB
testcase_22 AC 108 ms
6,768 KB
testcase_23 AC 208 ms
12,104 KB
testcase_24 AC 114 ms
6,924 KB
testcase_25 AC 195 ms
12,128 KB
testcase_26 AC 159 ms
11,140 KB
testcase_27 AC 191 ms
12,132 KB
testcase_28 AC 148 ms
8,352 KB
testcase_29 AC 190 ms
12,132 KB
testcase_30 AC 137 ms
8,208 KB
testcase_31 AC 193 ms
12,128 KB
testcase_32 AC 178 ms
11,720 KB
testcase_33 AC 196 ms
12,132 KB
testcase_34 AC 127 ms
7,836 KB
testcase_35 AC 195 ms
12,132 KB
testcase_36 AC 182 ms
11,720 KB
testcase_37 AC 195 ms
12,128 KB
testcase_38 AC 169 ms
11,348 KB
testcase_39 AC 199 ms
12,128 KB
testcase_40 AC 169 ms
11,148 KB
testcase_41 AC 194 ms
12,116 KB
testcase_42 AC 143 ms
8,400 KB
testcase_43 AC 205 ms
12,100 KB
testcase_44 AC 98 ms
6,400 KB
testcase_45 AC 190 ms
12,076 KB
testcase_46 AC 175 ms
11,632 KB
testcase_47 AC 192 ms
12,152 KB
testcase_48 AC 115 ms
7,044 KB
testcase_49 AC 205 ms
12,076 KB
testcase_50 AC 116 ms
6,984 KB
testcase_51 AC 190 ms
12,136 KB
testcase_52 AC 161 ms
8,560 KB
testcase_53 AC 195 ms
12,516 KB
testcase_54 AC 201 ms
12,516 KB
testcase_55 AC 204 ms
12,516 KB
testcase_56 AC 203 ms
12,516 KB
testcase_57 AC 105 ms
6,796 KB
testcase_58 AC 140 ms
8,576 KB
testcase_59 AC 129 ms
8,236 KB
testcase_60 AC 109 ms
7,264 KB
testcase_61 AC 99 ms
6,640 KB
testcase_62 AC 161 ms
12,416 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
testcase_65 AC 1 ms
5,376 KB
testcase_66 AC 1 ms
5,376 KB
testcase_67 AC 1 ms
5,376 KB
testcase_68 AC 1 ms
5,376 KB
testcase_69 AC 1 ms
5,376 KB
testcase_70 AC 1 ms
5,376 KB
testcase_71 AC 1 ms
5,376 KB
testcase_72 AC 1 ms
5,376 KB
testcase_73 AC 1 ms
5,376 KB
testcase_74 AC 1 ms
5,376 KB
testcase_75 AC 1 ms
5,376 KB
testcase_76 AC 1 ms
5,376 KB
testcase_77 AC 1 ms
5,376 KB
testcase_78 AC 1 ms
5,376 KB
testcase_79 AC 1 ms
5,376 KB
testcase_80 AC 1 ms
5,376 KB
testcase_81 AC 1 ms
5,376 KB
testcase_82 AC 1 ms
5,376 KB
testcase_83 AC 1 ms
5,376 KB
testcase_84 AC 1 ms
5,376 KB
testcase_85 AC 1 ms
5,376 KB
testcase_86 AC 1 ms
5,376 KB
testcase_87 AC 1 ms
5,376 KB
testcase_88 AC 1 ms
5,376 KB
testcase_89 AC 1 ms
5,376 KB
testcase_90 AC 1 ms
5,376 KB
testcase_91 AC 1 ms
5,376 KB
testcase_92 AC 1 ms
5,376 KB
testcase_93 AC 1 ms
5,376 KB
testcase_94 AC 1 ms
5,376 KB
testcase_95 AC 1 ms
5,376 KB
testcase_96 AC 1 ms
5,376 KB
testcase_97 AC 1 ms
5,376 KB
testcase_98 AC 2 ms
5,376 KB
testcase_99 AC 1 ms
5,376 KB
testcase_100 AC 1 ms
5,376 KB
testcase_101 AC 1 ms
5,376 KB
testcase_102 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt;
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt;
      }
      
      int[][2] ans;
      if (N <= 4) {
        alias Entry = Tuple!(int, "val", int[], "ps");
        Entry[] es;
        auto ps = iota(1, N + 1).array;
        do {
          int val;
          foreach (i; 0 .. N) {
            val ^= (ps[i] + A[i]);
          }
          es ~= Entry(val, ps.dup);
        } while (ps.nextPermutation);
        es.sort;
        foreach (h; 0 .. cast(int)(es.length) - 1) {
          if (es[h].val == es[h + 1].val) {
            ans[0] = es[h].ps;
            ans[1] = es[h + 1].ps;
            break;
          }
        }
      } else {
        auto iss = new int[][4];
        foreach (i; 0 .. N) {
          iss[A[i] % 4] ~= i;
        }
        foreach (r; 0 .. 4) if (iss[r].length >= 2) {
          ans[0] = new int[N];
          ans[0][] = -1;
          ans[0][iss[r][0]] = 1;
          ans[0][iss[r][1]] = 2;
          int now = 3;
          foreach (i; 0 .. N) if (!~ans[0][i]) {
            ans[0][i] = now++;
          }
          ans[1] = ans[0].dup;
          swap(ans[1][iss[r][0]], ans[1][iss[r][1]]);
          break;
        }
      }
      
      if (ans[0]) {
        foreach (h; 0 .. 2) {
          foreach (i; 0 .. N) {
            if (i) write(" ");
            write(ans[h][i]);
          }
          writeln;
        }
      } else {
        writeln(-1);
      }
    }
  } catch (EOFException e) {
  }
}
0