結果

問題 No.1061 素敵な数列
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-05-22 22:37:25
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 4,907 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 109,048 KB
実行使用メモリ 7,768 KB
最終ジャッジ日時 2023-09-04 07:54:03
合計ジャッジ時間 7,508 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 46 ms
4,380 KB
testcase_20 AC 37 ms
4,380 KB
testcase_21 AC 84 ms
4,632 KB
testcase_22 AC 161 ms
6,652 KB
testcase_23 AC 123 ms
6,960 KB
testcase_24 AC 127 ms
6,776 KB
testcase_25 AC 124 ms
7,380 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 71 ms
5,388 KB
testcase_28 AC 80 ms
5,844 KB
testcase_29 AC 117 ms
6,536 KB
testcase_30 AC 142 ms
6,932 KB
testcase_31 AC 76 ms
5,392 KB
testcase_32 AC 176 ms
7,768 KB
testcase_33 AC 27 ms
4,380 KB
testcase_34 AC 41 ms
5,388 KB
testcase_35 AC 39 ms
4,380 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; }
real readReal() { return readToken.to!real; }

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() {
  /*
  debug {
    foreach (n; 1 .. 10 + 1) {
      int[] perm;
      foreach (i; 0 .. n) {
        perm ~= i;
        perm ~= i;
        perm ~= i;
      }
      do {
        auto poss = new int[][n];
        foreach (i; 0 .. n * 3) {
          // poss[perm[i]] ~= i;
          poss[perm[i]] ~= ((i == n * 3 - 1) ? (n * 3) : i);
        }
        bool ok = true;
        foreach (j; 0 .. n) {
          ok = ok && (abs((poss[j][1] - poss[j][0] - 1) - (poss[j][2] - poss[j][1] - 1)) == j);
        }
        if (ok) {
          writeln(perm);
          stdout.flush;
          break;
        }
      } while (perm.nextPermutation);
    }
  }
  //*/
/*
[0, 0, 0]
[0, 0, 0, 1, 2, 1, 1, 2, 2]
[0, 0, 0, 1, 1, 3, 1, 2, 2, 3, 3, 2]
[0, 0, 0, 1, 1, 2, 1, 3, 4, 4, 2, 3, 3, 2, 4]
[0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 5, 2, 3, 3, 4, 4, 5, 5]

[0, 0, 0, 1, 1, 1]
[0, 0, 0, 2, 1, 2, 1, 1, 2]
[0, 0, 0, 1, 2, 3, 1, 2, 1, 3, 3, 2]
[0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 4, 2, 3, 3, 4]
[0, 0, 0, 1, 1, 2, 1, 3, 2, 3, 4, 5, 5, 2, 3, 4, 4, 5]
*/
  
  try {
    for (; ; ) {
      const N = readInt();
      if (N == 2) {
        writeln(-1);
        continue;
      }
      
      int[] fs, gs;
      for (int a = N - 1; ; ) {
        if (gs.length % 2 == 0) {
          if (a == 0 || a == 2 || a == 3 || a == 4 || a == 5) {
            fs ~= a;
            break;
          }
        } else {
          if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5) {
            gs ~= a;
            break;
          }
        }
        if (a % 2 == 0) {
          fs ~= a;
        } else {
          gs ~= a;
        }
        a = a / 2 - 1;
      }
      debug {
        writeln("fs = ", fs);
        writeln("gs = ", gs);
      }
      
      int[] ans;
      foreach (f; fs) {
        switch (f) {
          case 0: ans ~= [0, 0, 0]; break;
          case 2: ans ~= [0, 0, 0, 1, 2, 1, 1, 2, 2]; break;
          case 3: ans ~= [0, 0, 0, 1, 1, 3, 1, 2, 2, 3, 3, 2]; break;
          case 4: ans ~= [0, 0, 0, 1, 1, 2, 1, 3, 4, 4, 2, 3, 3, 2, 4]; break;
          case 5: ans ~= [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 5, 2, 3, 3, 4, 4, 5, 5]; break;
          default: {
            foreach_reverse (i; f / 2 .. f + 1) {
              ans ~= i;
              ans ~= i;
            }
            foreach_reverse (i; f / 2 .. f + 1) {
              ans ~= i;
            }
          }
        }
      }
      foreach (j, g; gs) {
        const head = cast(int)(ans.length);
        switch (g) {
          case 1: ans ~= [0, 0, 0, 1, 1, 1]; break;
          case 2: ans ~= [0, 0, 0, 2, 1, 2, 1, 1, 2]; break;
          case 3: ans ~= [0, 0, 0, 1, 2, 3, 1, 2, 1, 3, 3, 2]; break;
          case 4: ans ~= [0, 0, 0, 1, 1, 2, 1, 2, 3, 4, 4, 2, 3, 3, 4]; break;
          case 5: ans ~= [0, 0, 0, 1, 1, 2, 1, 3, 2, 3, 4, 5, 5, 2, 3, 4, 4, 5]; break;
          default: {
            foreach_reverse (i; g / 2 + 1 .. g + 1) {
              ans ~= i;
              ans ~= i;
            }
            ans ~= g / 2;
            foreach_reverse (i; g / 2 + 1 .. g + 1) {
              ans ~= i;
            }
            ans ~= g / 2;
            ans ~= g / 2;
          }
        }
        const tail = cast(int)(ans.length);
        if (j % 2 != 0) {
          ans[head .. tail].reverse;
          swap(ans[head - 1], ans[head]);
        }
      }
      
      assert(ans.length == N * 3);
      foreach (j; 0 .. N * 3) {
        if (j > 0) write(" ");
        write(ans[j]);
      }
      writeln();
      
      auto poss = new int[][N];
      foreach (j; 0 .. N * 3) {
        poss[ans[j]] ~= j;
      }
      foreach (j; 0 .. N) {
        assert(abs((poss[j][1] - poss[j][0] - 1) - (poss[j][2] - poss[j][1] - 1)) == j);
      }
    }
  } catch (EOFException e) {
  }
}
0