結果

問題 No.1306 Exactly 2 Digits
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-12-03 00:56:18
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 4,174 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 174,968 KB
実行使用メモリ 25,832 KB
平均クエリ数 1104.57
最終ジャッジ日時 2024-06-22 10:12:52
合計ジャッジ時間 20,735 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
25,196 KB
testcase_01 AC 19 ms
25,196 KB
testcase_02 AC 19 ms
25,208 KB
testcase_03 AC 18 ms
25,220 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 22 ms
24,836 KB
testcase_07 AC 19 ms
24,580 KB
testcase_08 AC 20 ms
24,580 KB
testcase_09 AC 19 ms
25,220 KB
testcase_10 AC 19 ms
25,220 KB
testcase_11 AC 18 ms
24,964 KB
testcase_12 RE -
testcase_13 AC 19 ms
25,040 KB
testcase_14 AC 19 ms
24,556 KB
testcase_15 AC 21 ms
24,812 KB
testcase_16 RE -
testcase_17 AC 19 ms
25,196 KB
testcase_18 RE -
testcase_19 AC 19 ms
24,812 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 19 ms
24,812 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 21 ms
25,196 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 19 ms
25,196 KB
testcase_29 AC 21 ms
25,180 KB
testcase_30 RE -
testcase_31 AC 19 ms
25,196 KB
testcase_32 AC 20 ms
24,812 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 20 ms
24,812 KB
testcase_36 RE -
testcase_37 AC 19 ms
25,196 KB
testcase_38 AC 20 ms
24,940 KB
testcase_39 AC 21 ms
24,812 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 22 ms
25,448 KB
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 22 ms
25,452 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 27 ms
24,812 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 30 ms
25,196 KB
testcase_55 RE -
testcase_56 AC 34 ms
25,196 KB
testcase_57 RE -
testcase_58 RE -
testcase_59 AC 36 ms
24,940 KB
testcase_60 RE -
testcase_61 AC 45 ms
25,196 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 AC 58 ms
25,196 KB
testcase_69 AC 60 ms
24,812 KB
testcase_70 AC 61 ms
24,556 KB
testcase_71 RE -
testcase_72 AC 61 ms
24,940 KB
testcase_73 AC 61 ms
25,160 KB
testcase_74 RE -
testcase_75 AC 68 ms
24,812 KB
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 AC 103 ms
24,940 KB
testcase_81 AC 85 ms
24,812 KB
testcase_82 AC 110 ms
24,940 KB
testcase_83 AC 108 ms
24,812 KB
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 102 ms
24,556 KB
testcase_87 RE -
testcase_88 RE -
testcase_89 AC 108 ms
24,556 KB
testcase_90 AC 97 ms
24,812 KB
testcase_91 AC 105 ms
24,812 KB
testcase_92 AC 98 ms
24,556 KB
testcase_93 RE -
testcase_94 RE -
testcase_95 AC 103 ms
24,556 KB
testcase_96 AC 96 ms
24,940 KB
testcase_97 RE -
testcase_98 RE -
testcase_99 AC 109 ms
24,940 KB
testcase_100 RE -
testcase_101 RE -
testcase_102 AC 96 ms
24,556 KB
testcase_103 AC 104 ms
24,940 KB
testcase_104 RE -
testcase_105 AC 104 ms
25,472 KB
testcase_106 AC 90 ms
25,196 KB
testcase_107 AC 106 ms
25,196 KB
testcase_108 AC 97 ms
25,196 KB
testcase_109 RE -
testcase_110 RE -
testcase_111 RE -
testcase_112 RE -
testcase_113 RE -
testcase_114 RE -
testcase_115 RE -
testcase_116 AC 128 ms
24,796 KB
testcase_117 AC 115 ms
25,196 KB
testcase_118 AC 115 ms
25,196 KB
testcase_119 AC 100 ms
24,940 KB
testcase_120 RE -
testcase_121 RE -
testcase_122 RE -
権限があれば一括ダウンロードができます

ソースコード

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 nice = -1;
  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;
          const res = Ask(nice, i);
          debug {
            writeln(i, " ", j, " ", nice, ": ", res);
          }
          if ((ans[nice] / N - x1 == res.p && ans[nice] % N - y1 == res.q) ||
              (ans[nice] / N - x1 == res.q && ans[nice] % N - y1 == res.p)) {
            ans[i] = x1 * N + y1;
            ans[j] = x2 * N + y2;
          } else {
            ans[i] = x2 * N + y2;
            ans[j] = x1 * N + y1;
          }
        }
      } else {
        assert(false);
      }
    }
    if (phase == 0) {
      foreach (i; 0 .. N^^2 - N) {
        if (ans[i] == 1 * N + (N - 1)) {
          nice = i;
        }
      }
      assert(nice != -1);
    }
  }
  
  write("!");
  foreach (i; 0 .. N^^2 - N) {
    write(" ", ans[i]);
  }
  writeln;
  stdout.flush;
  debug {
    assert(A == ans);
  }
}
0