結果

問題 No.2577 Simple Permutation Guess
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-12-06 00:33:45
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 437 ms / 2,000 ms
コード長 2,162 bytes
コンパイル時間 3,998 ms
コンパイル使用メモリ 109,440 KB
実行使用メモリ 24,012 KB
平均クエリ数 248.84
最終ジャッジ日時 2023-12-06 00:34:16
合計ジャッジ時間 29,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,000 KB
testcase_01 AC 297 ms
24,000 KB
testcase_02 AC 67 ms
24,000 KB
testcase_03 AC 25 ms
24,000 KB
testcase_04 AC 101 ms
24,000 KB
testcase_05 AC 123 ms
24,000 KB
testcase_06 AC 437 ms
24,000 KB
testcase_07 AC 411 ms
24,000 KB
testcase_08 AC 414 ms
24,000 KB
testcase_09 AC 413 ms
24,000 KB
testcase_10 AC 425 ms
24,000 KB
testcase_11 AC 28 ms
24,000 KB
testcase_12 AC 29 ms
24,000 KB
testcase_13 AC 30 ms
24,000 KB
testcase_14 AC 29 ms
24,000 KB
testcase_15 AC 27 ms
24,000 KB
testcase_16 AC 28 ms
24,000 KB
testcase_17 AC 26 ms
24,000 KB
testcase_18 AC 27 ms
24,000 KB
testcase_19 AC 25 ms
24,000 KB
testcase_20 AC 28 ms
24,000 KB
testcase_21 AC 28 ms
24,000 KB
testcase_22 AC 25 ms
24,012 KB
testcase_23 AC 30 ms
24,012 KB
testcase_24 AC 25 ms
24,012 KB
testcase_25 AC 25 ms
24,012 KB
testcase_26 AC 26 ms
24,012 KB
testcase_27 AC 25 ms
24,012 KB
testcase_28 AC 25 ms
24,012 KB
testcase_29 AC 26 ms
24,012 KB
testcase_30 AC 28 ms
24,012 KB
testcase_31 AC 25 ms
24,000 KB
testcase_32 AC 25 ms
24,000 KB
testcase_33 AC 25 ms
24,000 KB
testcase_34 AC 25 ms
24,000 KB
testcase_35 AC 25 ms
24,000 KB
testcase_36 AC 30 ms
24,000 KB
testcase_37 AC 29 ms
24,000 KB
testcase_38 AC 27 ms
24,000 KB
testcase_39 AC 25 ms
24,000 KB
testcase_40 AC 25 ms
24,000 KB
testcase_41 AC 25 ms
24,000 KB
testcase_42 AC 25 ms
24,000 KB
testcase_43 AC 24 ms
24,000 KB
testcase_44 AC 25 ms
24,000 KB
testcase_45 AC 25 ms
24,000 KB
testcase_46 AC 32 ms
24,000 KB
testcase_47 AC 26 ms
24,000 KB
testcase_48 AC 25 ms
24,000 KB
testcase_49 AC 30 ms
24,000 KB
testcase_50 AC 25 ms
24,000 KB
testcase_51 AC 26 ms
24,000 KB
testcase_52 AC 25 ms
24,000 KB
testcase_53 AC 25 ms
24,000 KB
testcase_54 AC 26 ms
24,000 KB
testcase_55 AC 26 ms
24,000 KB
testcase_56 AC 27 ms
24,000 KB
testcase_57 AC 29 ms
24,000 KB
testcase_58 AC 29 ms
24,000 KB
testcase_59 AC 27 ms
24,000 KB
testcase_60 AC 26 ms
24,000 KB
testcase_61 AC 27 ms
24,000 KB
testcase_62 AC 27 ms
24,000 KB
testcase_63 AC 29 ms
24,000 KB
testcase_64 AC 29 ms
24,012 KB
testcase_65 AC 31 ms
24,012 KB
testcase_66 AC 24 ms
24,012 KB
testcase_67 AC 24 ms
24,012 KB
testcase_68 AC 28 ms
24,012 KB
testcase_69 AC 25 ms
24,012 KB
testcase_70 AC 25 ms
24,012 KB
testcase_71 AC 29 ms
24,012 KB
testcase_72 AC 28 ms
24,012 KB
testcase_73 AC 30 ms
24,000 KB
testcase_74 AC 28 ms
24,000 KB
testcase_75 AC 32 ms
24,000 KB
testcase_76 AC 30 ms
24,000 KB
testcase_77 AC 32 ms
24,000 KB
testcase_78 AC 30 ms
24,000 KB
testcase_79 AC 32 ms
24,000 KB
testcase_80 AC 31 ms
24,000 KB
testcase_81 AC 30 ms
24,000 KB
testcase_82 AC 31 ms
24,000 KB
testcase_83 AC 31 ms
24,000 KB
testcase_84 AC 34 ms
24,000 KB
testcase_85 AC 28 ms
24,000 KB
testcase_86 AC 30 ms
24,000 KB
testcase_87 AC 28 ms
24,012 KB
testcase_88 AC 28 ms
24,012 KB
testcase_89 AC 36 ms
24,012 KB
testcase_90 AC 29 ms
24,012 KB
testcase_91 AC 32 ms
24,012 KB
testcase_92 AC 309 ms
24,012 KB
testcase_93 AC 313 ms
24,012 KB
testcase_94 AC 258 ms
24,012 KB
testcase_95 AC 390 ms
24,012 KB
testcase_96 AC 396 ms
24,012 KB
testcase_97 AC 364 ms
24,012 KB
testcase_98 AC 353 ms
24,012 KB
testcase_99 AC 376 ms
24,012 KB
testcase_100 AC 307 ms
24,012 KB
testcase_101 AC 356 ms
24,012 KB
evil_1_rnd_1.txt AC 954 ms
24,012 KB
evil_1_rnd_2.txt AC 951 ms
24,012 KB
evil_2_big_1.txt AC 1,316 ms
24,012 KB
evil_2_big_2.txt AC 1,283 ms
24,012 KB
evil_2_big_3.txt AC 1,333 ms
24,012 KB
evil_3_sorted_1.txt AC 515 ms
24,012 KB
evil_4_sorted_rev_1.txt AC 376 ms
24,012 KB
evil_4_sorted_rev_2.txt AC 574 ms
24,012 KB
evil_400_sorted.txt AC 1,023 ms
24,012 KB
evil_400_sorted_rev.txt AC 1,074 ms
24,012 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)); }


int N;

int Ask(int[] qs) {
  write("?");
  foreach (i; 0 .. N) write(" ", qs[i] + 1);
  writeln;
  stdout.flush;
  const ret = readInt;
  return ret;
}

void Answer(int[] ps) {
  write("!");
  foreach (i; 0 .. N) write(" ", ps[i] + 1);
  writeln;
  stdout.flush;
}

// \sum[0<=i<N] xs[N-1-i] i!
int[] toPerm(int[] xs) {
  auto ps = xs.dup;
  foreach_reverse (i; 0 .. N) foreach (j; i + 1 .. N) if (ps[i] <= ps[j]) ++ps[j];
// writeln(xs,": ",ps);
  return ps;
}

void main() {
  N = readInt;
  
  auto lo = new int[N];
  auto hi = new int[N];
  hi[0] = N;
  for (; ; ) {
    auto mid = new int[N];
    {
      int carry;
      foreach (i; 0 .. N) {
        mid[i] = (lo[i] + hi[i] + carry) / 2;
        carry = (lo[i] + hi[i] + carry) % 2 * (N - 1 - i);
      }
      foreach_reverse (i; 1 .. N) {
        mid[i - 1] += mid[i] / (N - i);
        mid[i] %= (N - i);
      }
    }
    if (lo == mid) break;
    (Ask(toPerm(mid)) ? lo : hi) = mid;
  }
  
  Answer(toPerm(lo));
}
0