結果

問題 No.814 ジジ抜き
ユーザー te-shte-sh
提出日時 2021-06-17 13:21:59
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 254 ms / 3,000 ms
コード長 3,000 bytes
コンパイル時間 2,924 ms
コンパイル使用メモリ 211,580 KB
実行使用メモリ 12,656 KB
最終ジャッジ日時 2023-09-04 12:58:30
合計ジャッジ時間 8,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 225 ms
10,852 KB
testcase_05 AC 228 ms
12,120 KB
testcase_06 AC 253 ms
12,656 KB
testcase_07 AC 131 ms
8,068 KB
testcase_08 AC 244 ms
10,884 KB
testcase_09 AC 180 ms
9,344 KB
testcase_10 AC 245 ms
11,136 KB
testcase_11 AC 246 ms
11,148 KB
testcase_12 AC 124 ms
7,232 KB
testcase_13 AC 126 ms
7,760 KB
testcase_14 AC 189 ms
8,832 KB
testcase_15 AC 97 ms
7,032 KB
testcase_16 AC 99 ms
6,732 KB
testcase_17 AC 202 ms
9,372 KB
testcase_18 AC 171 ms
8,244 KB
testcase_19 AC 254 ms
12,116 KB
testcase_20 AC 128 ms
7,780 KB
testcase_21 AC 143 ms
7,780 KB
testcase_22 AC 211 ms
9,100 KB
testcase_23 AC 109 ms
6,996 KB
testcase_24 AC 189 ms
8,608 KB
testcase_25 AC 147 ms
7,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// URL: https://yukicoder.me/problems/no/814

import std;

version(unittest) {} else
void main()
{
  int N; io.getV(N);
  long[] K, L; int[] D; io.getC(N, K, L, D);

  auto r = 0L;
  foreach (Ki, Li, Di; lockstep(K, L, D)) {
    auto x1 = Ki%2 == 0 ? 0 : Li & ((1L<<Di)-1);
    auto x2 = cumulativeXOR(Li>>Di, (Li>>Di)+(Ki-1))<<Di;
    r ^= (x1 | x2);
  }

  io.put(r);
}

auto cumulativeXOR(long n1, long n2)
{
  auto r = cumulativeXOR(n2);
  return n1 == 0 ? r : r ^ cumulativeXOR(n1-1);
}

auto cumulativeXOR(long n)
{
  switch (n%4) {
  case 0: return n;
  case 1: return 1;
  case 2: return n+1;
  case 3: return 0;
  default: assert(0);
  }
}

auto io = IO!()();
struct IO(alias IN = stdin, alias OUT = stdout)
{
  import core.stdc.stdlib : exit;

  void getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }
  void getA(T)(size_t n, ref T v)
    if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }
  void getC(T...)(size_t n, ref T v)
    if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v) w = new typeof(w)(n);
    foreach (i; 0..n) foreach (ref w; v) get(w[i]);
  }
  void getM(T)(size_t r, size_t c, ref T v)
    if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }
  template getS(E...)
  {
    void getS(T)(size_t n, ref T v)
    {
      v = new T(n);
      foreach (ref w; v) foreach (e; E) mixin("get(w."~e~");");
    }
  }

  const struct PutConf
  {
    bool newline = true, flush, exit;
    string floatFormat = "%.10f", delimiter = " ";
  }

  void put(alias conf = "{}", T...)(T v)
  {
    putMain!conf(v);
  }
  void putB(alias conf = "{}", S, T)(bool c, S t, T f)
  {
    if (c) put!conf(t);
    else put!conf(f);
  }
  void putRaw(T...)(T v)
  {
    OUT.write(v);
    OUT.writeln;
  }

  private
  {
    dchar[] buf;
    auto sp = (new dchar[](0)).splitter;

    void nextLine()
    {
      IN.readln(buf);
      sp = buf.splitter;
    }
    void get(T)(ref T v)
    {
      if (sp.empty) nextLine();
      v = sp.front.to!T;
      sp.popFront();
    }

    void putMain(alias conf, T...)(T v)
    {
      mixin("const PutConf c = "~conf~";");
      foreach (i, w; v) {
        putOne!conf(w);
        if (i+1 < v.length) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    void putOne(alias conf, T)(T v)
    {
      mixin("const PutConf c = "~conf~";");
      static if (isInputRange!T && !isSomeString!T) putRange!conf(v);
      else static if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else static if (hasMember!(T, "fprint")) v.fprint(OUT);
      else OUT.write(v);
    }
    void putRange(alias conf, T)(T v)
    {
      mixin("const PutConf c = "~conf~";");
      auto w = v;
      while (!w.empty) {
        putOne!conf(w.front); w.popFront();
        if (!w.empty) OUT.write(c.delimiter);
      }
    }
  }
}
0