結果

問題 No.387 ハンコ
ユーザー te-shte-sh
提出日時 2017-07-25 17:03:01
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 22,652 KB
最終ジャッジ日時 2023-09-03 15:29:01
合計ジャッジ時間 13,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

void main()
{
  auto n = readln.chomp.to!size_t;

  auto a = new int[](n), rda = readln.chomp.splitter;
  foreach (i; 0..n) {
    a[i] = rda.front.to!int;
    rda.popFront();
  }

  auto b = new int[](n), rdb = readln.chomp.splitter;
  foreach (i; 0..n) {
    b[i] = rdb.front.to!int;
    rdb.popFront();
  }

  auto newBitArray() {
    auto r = BitArray();
    r.length = 2*n-1;
    return r;
  }

  auto shift(ref BitArray ba, size_t n)
  {
    if (n > 0 && n % 64 == 0) {
      ba <<= 1;
      ba <<= n-1;
    } else {
      ba <<= n;
    }
  }

  size_t[][int] c;
  foreach (i, ai; a) c[ai] ~= i;

  auto r = newBitArray();
  foreach (ci; c.byValue) {
    auto d = newBitArray();
    foreach (cii; ci) d[cii] = true;

    auto s = newBitArray(), p = size_t(0);
    foreach (i, bi; b) {
      if (bi) {
        shift(d, i - p);
        s |= d;
        p = i;
      }
    }
    r ^= s;
  }

  foreach (i; 0..2*n-1)
    writeln(r[i] ? "ODD" : "EVEN");
}
0