結果

問題 No.387 ハンコ
ユーザー te-shte-sh
提出日時 2017-07-25 16:58:43
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,048 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 819,132 KB
最終ジャッジ日時 2023-09-03 15:28:40
合計ジャッジ時間 9,965 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
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;
    }
  }

  BitArray[int] c;
  foreach (i, ai; a) {
    if (ai !in c) c[ai] = newBitArray();
    c[ai][i] = true;
  }

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

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