結果

問題 No.1123 Afforestation
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-07-23 19:53:44
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,200 ms / 2,500 ms
コード長 3,407 bytes
コンパイル時間 1,072 ms
コンパイル使用メモリ 116,108 KB
実行使用メモリ 14,244 KB
最終ジャッジ日時 2023-09-04 08:43:57
合計ジャッジ時間 17,995 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 15 ms
7,540 KB
testcase_05 AC 142 ms
11,108 KB
testcase_06 AC 416 ms
13,708 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 87 ms
10,376 KB
testcase_13 AC 967 ms
14,120 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 20 ms
6,700 KB
testcase_20 AC 256 ms
11,768 KB
testcase_21 AC 1,200 ms
14,036 KB
testcase_22 AC 1,095 ms
14,244 KB
testcase_23 AC 1,098 ms
14,224 KB
testcase_24 AC 1,145 ms
13,976 KB
testcase_25 AC 900 ms
13,796 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 76 ms
13,848 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 6 ms
9,080 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 4 ms
4,380 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 4 ms
4,376 KB
testcase_42 AC 12 ms
4,384 KB
testcase_43 AC 27 ms
5,668 KB
testcase_44 AC 52 ms
4,944 KB
testcase_45 AC 52 ms
4,948 KB
testcase_46 AC 68 ms
5,068 KB
testcase_47 AC 70 ms
5,028 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 AC 3 ms
4,384 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 1 ms
4,380 KB
testcase_55 AC 4 ms
4,380 KB
testcase_56 AC 5 ms
4,380 KB
testcase_57 AC 4 ms
4,380 KB
testcase_58 AC 13 ms
4,376 KB
testcase_59 AC 25 ms
5,936 KB
testcase_60 AC 56 ms
4,976 KB
testcase_61 AC 58 ms
4,956 KB
testcase_62 AC 74 ms
4,960 KB
testcase_63 AC 72 ms
6,228 KB
testcase_64 AC 1 ms
4,504 KB
testcase_65 AC 2 ms
4,380 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 4 ms
4,384 KB
testcase_69 AC 7 ms
4,380 KB
testcase_70 AC 11 ms
4,380 KB
testcase_71 AC 29 ms
6,012 KB
testcase_72 AC 1 ms
4,380 KB
testcase_73 AC 1 ms
4,380 KB
testcase_74 AC 2 ms
4,380 KB
testcase_75 AC 2 ms
4,380 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 1 ms
4,380 KB
testcase_78 AC 1 ms
4,380 KB
testcase_79 AC 2 ms
4,376 KB
testcase_80 AC 2 ms
4,380 KB
testcase_81 AC 2 ms
4,380 KB
testcase_82 AC 1 ms
4,380 KB
testcase_83 AC 2 ms
4,376 KB
testcase_84 AC 201 ms
12,204 KB
testcase_85 AC 275 ms
12,928 KB
testcase_86 AC 1 ms
4,380 KB
testcase_87 AC 1 ms
4,384 KB
testcase_88 AC 184 ms
12,452 KB
testcase_89 AC 185 ms
12,056 KB
testcase_90 AC 2 ms
4,380 KB
testcase_91 AC 1 ms
4,376 KB
testcase_92 AC 2 ms
4,380 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)); }


int H, W;
int[] A, B;
int K;
int[] X, Y;

char[][] ans;
int[] prev0, prev1;

void dfs0(int x) {
  foreach (y; 0 .. W) {
    if (ans[x][y] == '.') {
      if (prev1[y] == -1) {
        prev1[y] = x;
        dfs1(y);
      }
    }
  }
}
void dfs1(int y) {
  foreach (x; 0 .. H) {
    if (ans[x][y] == 'o') {
      if (prev0[x] == -1) {
        prev0[x] = y;
        dfs0(x);
      }
    }
  }
}

bool solve() {
  ans = new char[][](H, W);
  foreach (x; 0 .. H) {
    ans[x][] = '.';
  }
  
  auto axs = new Tuple!(int, int)[H];
  foreach (x; 0 .. H) {
    axs[x] = tuple(A[x], x);
  }
  axs.sort;
  auto bs = B.dup;
  foreach_reverse (ax; axs) {
    const x = ax[1];
    auto yss = new int[][H + 1];
    foreach (y; 0 .. W) {
      yss[bs[y]] ~= y;
    }
    int a = A[x];
    foreach_reverse (b; 1 .. H + 1) {
      foreach (y; yss[b]) {
        if (a > 0) {
          ans[x][y] = 'o';
          --a;
          --bs[y];
        }
      }
    }
    if (a != 0) {
      return false;
    }
  }
  if (!bs.all!"a == 0") {
    return false;
  }
  debug {
    writeln("ans = ", ans);
  }
  
  prev0 = new int[H];
  prev1 = new int[W];
  foreach (k; 0 .. K) {
    if (ans[X[k]][Y[k]] == 'o') {
      ans[X[k]][Y[k]] = 'x';
      prev0[] = -1;
      prev1[] = -1;
      dfs0(X[k]);
      if (prev1[Y[k]] == -1) {
        return false;
      }
      for (int y = Y[k]; ; ) {
        const x = prev1[y];
        ans[x][y] = 'o';
        if (x == X[k]) {
          break;
        }
        y = prev0[x];
        ans[x][y] = '.';
      }
    } else {
      ans[X[k]][Y[k]] = 'x';
    }
  }
  return true;
}

void main() {
  try {
    for (; ; ) {
      H = readInt();
      W = readInt();
      A = new int[H];
      foreach (x; 0 .. H) {
        A[x] = readInt();
      }
      B = new int[W];
      foreach (y; 0 .. W) {
        B[y] = readInt();
      }
      K = readInt();
      X = new int[K];
      Y = new int[K];
      foreach (k; 0 .. K) {
        X[k] = readInt() - 1;
        Y[k] = readInt() - 1;
      }
      
      const res = solve();
      if (res) {
        writeln("Yay!");
        foreach (x; 0 .. H) {
          writeln(ans[x]);
        }
      } else {
        writeln(":(");
      }
    }
  } catch (EOFException e) {
  }
}
0