結果

問題 No.1881 Everything is the same...
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-04-11 22:53:04
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 4,789 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 186,168 KB
実行使用メモリ 17,352 KB
最終ジャッジ日時 2024-06-22 14:53:45
合計ジャッジ時間 11,473 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 25 ms
7,464 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 240 ms
15,132 KB
testcase_11 AC 342 ms
17,352 KB
testcase_12 AC 236 ms
15,004 KB
testcase_13 AC 252 ms
14,980 KB
testcase_14 AC 251 ms
15,144 KB
testcase_15 AC 242 ms
15,108 KB
testcase_16 AC 241 ms
15,148 KB
testcase_17 AC 243 ms
15,128 KB
testcase_18 AC 233 ms
15,176 KB
testcase_19 AC 249 ms
15,132 KB
testcase_20 AC 240 ms
14,984 KB
testcase_21 AC 242 ms
15,052 KB
testcase_22 AC 240 ms
15,144 KB
testcase_23 AC 249 ms
15,076 KB
testcase_24 AC 243 ms
15,128 KB
testcase_25 AC 253 ms
15,144 KB
testcase_26 AC 252 ms
14,984 KB
testcase_27 AC 250 ms
15,096 KB
testcase_28 AC 246 ms
15,104 KB
testcase_29 AC 252 ms
15,184 KB
testcase_30 AC 244 ms
15,208 KB
testcase_31 AC 257 ms
15,032 KB
testcase_32 AC 245 ms
15,144 KB
testcase_33 AC 249 ms
15,032 KB
testcase_34 AC 246 ms
14,988 KB
testcase_35 AC 249 ms
15,032 KB
testcase_36 AC 248 ms
15,144 KB
testcase_37 AC 244 ms
15,176 KB
testcase_38 AC 245 ms
15,100 KB
testcase_39 AC 248 ms
15,196 KB
testcase_40 AC 245 ms
14,984 KB
testcase_41 AC 248 ms
15,148 KB
testcase_42 AC 3 ms
6,944 KB
testcase_43 AC 4 ms
6,940 KB
testcase_44 AC 3 ms
6,944 KB
testcase_45 AC 3 ms
6,940 KB
testcase_46 AC 3 ms
6,940 KB
testcase_47 AC 3 ms
6,940 KB
testcase_48 AC 3 ms
6,944 KB
testcase_49 AC 3 ms
6,940 KB
testcase_50 AC 3 ms
6,940 KB
testcase_51 AC 3 ms
6,940 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