結果

問題 No.1306 Exactly 2 Digits
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-12-03 01:00:50
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 4,486 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 173,608 KB
実行使用メモリ 24,480 KB
平均クエリ数 1236.78
最終ジャッジ日時 2023-09-04 11:24:56
合計ジャッジ時間 16,772 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,012 KB
testcase_01 AC 25 ms
23,592 KB
testcase_02 AC 25 ms
24,300 KB
testcase_03 AC 25 ms
23,412 KB
testcase_04 AC 25 ms
23,436 KB
testcase_05 AC 26 ms
23,988 KB
testcase_06 AC 25 ms
23,316 KB
testcase_07 AC 25 ms
23,616 KB
testcase_08 AC 24 ms
23,580 KB
testcase_09 AC 25 ms
23,328 KB
testcase_10 AC 25 ms
24,180 KB
testcase_11 AC 24 ms
23,580 KB
testcase_12 AC 26 ms
24,348 KB
testcase_13 AC 26 ms
23,376 KB
testcase_14 AC 26 ms
23,784 KB
testcase_15 AC 26 ms
24,036 KB
testcase_16 AC 27 ms
24,348 KB
testcase_17 AC 27 ms
23,364 KB
testcase_18 AC 26 ms
23,460 KB
testcase_19 AC 25 ms
23,556 KB
testcase_20 AC 27 ms
24,336 KB
testcase_21 AC 26 ms
23,460 KB
testcase_22 AC 26 ms
23,928 KB
testcase_23 AC 26 ms
23,580 KB
testcase_24 AC 26 ms
23,460 KB
testcase_25 AC 25 ms
23,580 KB
testcase_26 AC 25 ms
24,000 KB
testcase_27 AC 26 ms
24,348 KB
testcase_28 AC 26 ms
23,880 KB
testcase_29 AC 26 ms
23,664 KB
testcase_30 AC 26 ms
24,000 KB
testcase_31 AC 26 ms
24,012 KB
testcase_32 AC 27 ms
23,460 KB
testcase_33 AC 27 ms
23,364 KB
testcase_34 AC 25 ms
23,592 KB
testcase_35 AC 26 ms
24,048 KB
testcase_36 AC 25 ms
24,300 KB
testcase_37 AC 26 ms
23,868 KB
testcase_38 AC 25 ms
24,480 KB
testcase_39 AC 25 ms
23,604 KB
testcase_40 AC 26 ms
24,300 KB
testcase_41 AC 26 ms
24,000 KB
testcase_42 AC 26 ms
24,000 KB
testcase_43 AC 27 ms
23,496 KB
testcase_44 AC 28 ms
24,360 KB
testcase_45 AC 28 ms
24,060 KB
testcase_46 AC 29 ms
23,988 KB
testcase_47 AC 29 ms
23,376 KB
testcase_48 AC 31 ms
23,604 KB
testcase_49 AC 31 ms
23,460 KB
testcase_50 AC 33 ms
23,940 KB
testcase_51 AC 34 ms
24,072 KB
testcase_52 AC 36 ms
23,316 KB
testcase_53 AC 38 ms
24,084 KB
testcase_54 AC 37 ms
23,868 KB
testcase_55 AC 40 ms
23,376 KB
testcase_56 AC 41 ms
23,868 KB
testcase_57 AC 43 ms
23,652 KB
testcase_58 AC 45 ms
23,436 KB
testcase_59 AC 46 ms
23,760 KB
testcase_60 AC 52 ms
24,216 KB
testcase_61 AC 56 ms
23,688 KB
testcase_62 AC 55 ms
24,312 KB
testcase_63 AC 60 ms
23,316 KB
testcase_64 AC 57 ms
24,240 KB
testcase_65 AC 61 ms
24,348 KB
testcase_66 AC 67 ms
23,412 KB
testcase_67 AC 67 ms
23,328 KB
testcase_68 AC 67 ms
23,772 KB
testcase_69 AC 72 ms
23,616 KB
testcase_70 AC 72 ms
23,760 KB
testcase_71 AC 77 ms
24,000 KB
testcase_72 AC 76 ms
23,688 KB
testcase_73 AC 74 ms
24,096 KB
testcase_74 AC 88 ms
23,364 KB
testcase_75 AC 83 ms
24,348 KB
testcase_76 AC 94 ms
24,312 KB
testcase_77 AC 100 ms
23,412 KB
testcase_78 AC 110 ms
24,288 KB
testcase_79 AC 116 ms
24,060 KB
testcase_80 AC 120 ms
23,484 KB
testcase_81 AC 99 ms
23,664 KB
testcase_82 AC 125 ms
24,060 KB
testcase_83 AC 128 ms
24,300 KB
testcase_84 AC 137 ms
23,328 KB
testcase_85 AC 144 ms
24,000 KB
testcase_86 AC 120 ms
24,312 KB
testcase_87 AC 126 ms
24,228 KB
testcase_88 AC 155 ms
24,024 KB
testcase_89 AC 129 ms
24,000 KB
testcase_90 AC 114 ms
23,544 KB
testcase_91 AC 126 ms
24,084 KB
testcase_92 AC 115 ms
23,412 KB
testcase_93 AC 133 ms
23,484 KB
testcase_94 AC 115 ms
23,484 KB
testcase_95 AC 122 ms
24,000 KB
testcase_96 AC 110 ms
23,592 KB
testcase_97 AC 112 ms
23,352 KB
testcase_98 AC 106 ms
23,472 KB
testcase_99 AC 125 ms
23,448 KB
testcase_100 AC 126 ms
23,580 KB
testcase_101 AC 136 ms
24,240 KB
testcase_102 AC 113 ms
23,376 KB
testcase_103 AC 120 ms
23,328 KB
testcase_104 AC 120 ms
23,364 KB
testcase_105 AC 121 ms
23,580 KB
testcase_106 AC 109 ms
24,060 KB
testcase_107 AC 124 ms
23,580 KB
testcase_108 AC 115 ms
24,300 KB
testcase_109 AC 139 ms
23,328 KB
testcase_110 AC 111 ms
24,096 KB
testcase_111 AC 116 ms
23,340 KB
testcase_112 AC 105 ms
24,384 KB
testcase_113 AC 144 ms
24,360 KB
testcase_114 AC 144 ms
23,580 KB
testcase_115 AC 122 ms
23,772 KB
testcase_116 AC 150 ms
23,460 KB
testcase_117 AC 125 ms
23,268 KB
testcase_118 AC 136 ms
24,408 KB
testcase_119 AC 117 ms
23,448 KB
testcase_120 AC 107 ms
24,348 KB
testcase_121 AC 129 ms
23,796 KB
testcase_122 AC 128 ms
23,424 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)); }


int N;
debug {
  int[] A;
}

alias Pair = Tuple!(int, "p", int, "q");
Pair Ask(int i, int j) {
  writefln("? %s %s", i + 1, j + 1);
  stdout.flush;
  int p, q;
  debug {
    p = A[i] / N - A[j] / N;
    q = A[i] % N - A[j] % N;
    if (p > q) {
      swap(p, q);
    }
  } else {
    p = readInt();
    q = readInt();
  }
  return Pair(p, q);
}

void main() {
  N = readInt();
  debug {
    A = new int[N^^2 - N];
    foreach (i; 0 .. N^^2 - N) {
      A[i] = readInt();
    }
  }
  
  auto ans = new int[N^^2 - N];
  ans[] = -1;
  
  alias Entry = Tuple!(Pair, "val", int, "id");
  Entry[] es;
  foreach (i; 1 .. N^^2 - N) {
    const res = Ask(i, 0);
    es ~= Entry(res, i);
  }
  const esLen = cast(int)(es.length);
  es.sort;
  debug {
    writeln("es = ", es);
  }
  
  Pair mn = Pair(0, 0);
  Pair mx = Pair(0, 0);
  foreach (ref e; es) {
    if (mn.p + mn.q > e.val.p + e.val.q) mn = e.val;
    if (mx.p + mx.q < e.val.p + e.val.q) mx = e.val;
  }
  debug {
    writeln("mn = ", mn);
    writeln("mx = ", mx);
  }
  int[] a0s;
  foreach (s; 0 .. 2) foreach (t; 0 .. 2) {
    const x0mn = 1 - (s ? mn.q : mn.p);
    const y0mn = 0 - (s ? mn.p : mn.q);
    const x0mx = N - 1 - (t ? mx.q : mx.p);
    const y0mx = N - 1 - (t ? mx.p : mx.q);
    debug {
      writefln("(%s, %s), (%s, %s)", x0mn, y0mn, x0mx, y0mx);
    }
    if (x0mn == x0mx && y0mn == y0mx) {
      a0s ~= x0mn * N + y0mn;
    }
  }
  a0s = a0s.sort.uniq.array;
  assert(a0s.length == 1);
  ans[0] = a0s[0];
  
  int[] nices;
  foreach (phase; 0 .. 2) {
    for (int x = 0, y; x < esLen; x = y) {
      for (y = x; y < esLen && es[x].val == es[y].val; ++y) {}
      const x1 = ans[0] / N + es[x].val.p;
      const y1 = ans[0] % N + es[x].val.q;
      const x2 = ans[0] / N + es[x].val.q;
      const y2 = ans[0] % N + es[x].val.p;
      if (y - x == 1) {
        if (phase == 0) {
          const i = es[x].id;
          if (1 <= x1 && x1 <= N - 1 && 0 <= y1 && y1 <= N - 1) {
            ans[i] = x1 * N + y1;
          } else {
            ans[i] = x2 * N + y2;
          }
        }
      } else if (y - x == 2) {
        if (phase == 1) {
          const i = es[x].id;
          const j = es[x + 1].id;
          foreach (k; nices) {
            Pair ex1 = Pair(x1 - ans[k] / N, y1 - ans[k] % N);
            Pair ex2 = Pair(x2 - ans[k] / N, y2 - ans[k] % N);
            if (ex1.p > ex1.q) swap(ex1.p, ex1.q);
            if (ex2.p > ex2.q) swap(ex2.p, ex2.q);
            if (ex1 != ex2) {
              const res = Ask(i, k);
              if (ex1 == res) {
                ans[i] = x1 * N + y1;
                ans[j] = x2 * N + y2;
              } else if (ex2 == res) {
                ans[i] = x2 * N + y2;
                ans[j] = x1 * N + y1;
              } else {
                assert(false);
              }
              goto found;
            }
          }
          assert(false);
         found:
        }
      } else {
        assert(false);
      }
    }
    if (phase == 0) {
      foreach (i; 0 .. N^^2 - N) if (ans[i] == 1 * N + 0) nices ~= i;
      foreach (i; 0 .. N^^2 - N) if (ans[i] == (N - 1) * N + (N - 1)) nices ~= i;
      assert(nices.length == 2);
    }
  }
  
  write("!");
  foreach (i; 0 .. N^^2 - N) {
    write(" ", ans[i]);
  }
  writeln;
  stdout.flush;
  debug {
    assert(A == ans);
  }
}
0