結果

問題 No.1881 Everything is the same...
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-11 22:53:04
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 4,789 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 180,696 KB
実行使用メモリ 17,936 KB
最終ジャッジ日時 2023-09-04 16:44:54
合計ジャッジ時間 14,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 30 ms
7,804 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 302 ms
15,400 KB
testcase_11 AC 432 ms
17,936 KB
testcase_12 AC 298 ms
15,404 KB
testcase_13 AC 313 ms
15,412 KB
testcase_14 AC 310 ms
15,540 KB
testcase_15 AC 299 ms
15,432 KB
testcase_16 AC 298 ms
15,524 KB
testcase_17 AC 302 ms
15,524 KB
testcase_18 AC 295 ms
15,520 KB
testcase_19 AC 309 ms
15,448 KB
testcase_20 AC 303 ms
15,452 KB
testcase_21 AC 302 ms
15,424 KB
testcase_22 AC 302 ms
15,448 KB
testcase_23 AC 309 ms
15,460 KB
testcase_24 AC 305 ms
15,460 KB
testcase_25 AC 314 ms
15,448 KB
testcase_26 AC 316 ms
15,528 KB
testcase_27 AC 302 ms
15,520 KB
testcase_28 AC 298 ms
15,456 KB
testcase_29 AC 311 ms
15,464 KB
testcase_30 AC 302 ms
15,452 KB
testcase_31 AC 312 ms
15,472 KB
testcase_32 AC 302 ms
15,464 KB
testcase_33 AC 308 ms
15,472 KB
testcase_34 AC 304 ms
15,468 KB
testcase_35 AC 305 ms
15,412 KB
testcase_36 AC 304 ms
15,516 KB
testcase_37 AC 308 ms
15,404 KB
testcase_38 AC 303 ms
15,404 KB
testcase_39 AC 305 ms
15,464 KB
testcase_40 AC 301 ms
15,480 KB
testcase_41 AC 302 ms
15,528 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 4 ms
4,384 KB
testcase_44 AC 4 ms
4,380 KB
testcase_45 AC 4 ms
4,376 KB
testcase_46 AC 4 ms
4,384 KB
testcase_47 AC 4 ms
4,380 KB
testcase_48 AC 4 ms
4,376 KB
testcase_49 AC 4 ms
4,376 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 4 ms
4,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; }
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)); }


/*
  (Z/p^a[1] * ... * Z/p^a[k]) / (p^b[1], ..., p^b[k])
  0 <= b[i] <= a[i]
  
  [ p^a[1]            ]
  [        ...        ]
  [            p^a[k] ]
  [ p^b[1] ... p^b[k] ]
  
  a >= c
    [ p^c ] = [  0 1       ] [ p^a ]
    [ 0   ] = [ -1 p^(a-c) ] [ p^c ]
  a <= c
    [ p^a ] = [  1       0 ] [ p^a ]
    [ 0   ] = [ -p^(c-a) 1 ] [ p^c ]
*/
void experiment() {
  void check(int[] as) {
    const n = cast(int)(as.length);
    auto prods = new int[n + 1];
    prods[0] = 1;
    foreach (i; 0 .. n) {
      prods[i + 1] = prods[i] * (as[i] + 1);
    }
    foreach (p; 0 .. prods[n]) {
      const bs = iota(n).map!(i => p / prods[i] % (as[i] + 1)).array;
      auto aas = new int[n];
      auto cs = bs.dup;
      // incr b[i] ==> can ignore non-diag entries for isom
      auto ord = iota(n).array.sort!((i, j) => (bs[i] < bs[j]));
      foreach (i; ord) {
        if (as[i] >= cs[i]) {
          aas[i] = cs[i];
          cs[] += (as[i] - cs[i]);
        } else {
          aas[i] = as[i];
        }
      }
      writeln(as, " ", bs, ": ", aas);
    }
  }
  void dfs(int[] as) {
    check(as);
    if (as.length < 4) {
      foreach (a; (as.empty ? 1 : as[$ - 1]) .. 4) {
        dfs(as ~ a);
      }
    }
  }
  dfs([]);
}


enum LIM = 10^^5 + 10;
int[] lpf;

int[string] cache;
int calc(int[][] ass) {
  const key = ass.to!string;
  auto ptr = (key in cache);
  if (ptr) return *ptr;
  
  bool[int] app;
  auto bss = new int[][ass.length];
  foreach (i; 0 .. ass.length) {
    bss[i] = new int[ass[i].length];
  }
  void check() {
    if (ass != bss) {
      auto bssRed = bss.map!(bs => bs.filter!"a > 0".array).filter!"!a.empty".array;
      bssRed.sort;
      const res = calc(bssRed);
      app[res] = true;
    }
  }
  
  void dfs(int i, int j) {
    if (i == ass.length) {
      check();
    } else if (j == ass[i].length) {
      dfs(i + 1, 0);
    } else {
      foreach (b; (j ? ass[i][j - 1] : 0) .. ass[i][j] + 1) {
        bss[i][j] = b;
        dfs(i, j + 1);
      }
    }
  }
  dfs(0, 0);
  
  int ret;
  for (ret = 0; ret in app; ++ret) {}
  debug {
    writeln(ass, ": ", ret);
    stdout.flush;
  }
  return cache[key] = ret;
}

// (Z/aZ)^*
int solve(int a) {
  int[][int] ess;
  for (; a > 1; ) {
    const p = lpf[a];
    int e;
    do {
      ++e;
      a /= p;
    } while (a % p == 0);
    if (p == 2) {
      if (e == 1) {
        // Z/1
      } else if (e == 2) {
        // Z/2
        ess[2] ~= 1;
      } else {
        // Z/2 * Z/2^(e-2)
        ess[2] ~= 1;
        ess[2] ~= e - 2;
      }
    } else {
      // Z/(p^(e-1) (p-1))
      if (e >= 2) {
        ess[p] ~= e - 1;
      }
      for (int b = p - 1; b > 1; ) {
        const q = lpf[b];
        int f;
        do {
          ++f;
          b /= q;
        } while (b % q == 0);
        ess[q] ~= f;
      }
    }
  }
  debug {
    writeln("ess = ", ess);
  }
  int[][] ass;
  foreach (p, es; ess) {
    es.sort;
    ass ~= es;
  }
  ass.sort;
  return calc(ass);
}

void main() {
  lpf = iota(LIM).array;
  foreach (p; 2 .. LIM) if (lpf[p] == p) {
    for (int n = 2 * p; n < LIM; n += p) chmin(lpf[n], p);
  }
  
  // experiment;
  
  /*
  foreach (a; 1 .. 10^^5 + 1) {
    const res = solve(a);
    // writeln(a, " ", solve(a));
    // stdout.flush;
  }
  writeln("|cache| = ", cache.length);
  stdout.flush;
  //*/
  
  try {
    for (; ; ) {
      const N = readInt;
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt;
      }
      
      int ans;
      foreach (i; 0 .. N) {
        ans ^= solve(A[i]);
      }
      writeln(ans ? "Y" : "X");
    }
  } catch (EOFException e) {
  }
}
0