結果

問題 No.179 塗り分け
ユーザー te-shte-sh
提出日時 2020-01-30 22:06:42
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 5,951 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 155,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 05:21:07
合計ジャッジ時間 3,607 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 32 ms
4,376 KB
testcase_09 AC 31 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 32 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 31 ms
4,376 KB
testcase_21 AC 34 ms
4,380 KB
testcase_22 AC 40 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 32 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 7 ms
4,376 KB
testcase_27 AC 32 ms
4,380 KB
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 32 ms
4,380 KB
testcase_30 AC 15 ms
4,376 KB
testcase_31 AC 32 ms
4,380 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 AC 32 ms
4,376 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 32 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 4 ms
4,376 KB
testcase_44 AC 8 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(149): Deprecation: function `Main.IO!(makeGlobal, makeGlobal).IO.put!("{exit: true}", string).put.putMain!(c, string).putMain` function requires a dual-context, which is deprecated
Main.d-mixin-137(137):        instantiated from here: `putMain!(c, string)`
Main.d(11):        instantiated from here: `put!("{exit: true}", string)`
Main.d(149): Deprecation: function `Main.IO!(makeGlobal, makeGlobal).IO.put!("{}", string).put.putMain!(c, string).putMain` function requires a dual-context, which is deprecated
Main.d-mixin-137(137):        instantiated from here: `putMain!(c, string)`
Main.d(33):        instantiated from here: `put!("{}", string)`

ソースコード

diff #

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

import std.algorithm, std.array, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int H, W; io.getV(H, W);
  string[] S; io.getC(H, S);

  if (S.map!"a.sum".sum == 0) io.put!"{exit: true}"("NO");

  auto a = grid(S.map!(l => l.map!(c => c == '.' ? 0 : 1).array).array);
  alias Point = a.Point;

  foreach (y; 0..H) {
  loop: foreach (x; -W+1..W) {
      auto b = a.dup, d = Point(x, y);
      foreach (by; 0..H)
        foreach (bx; 0..W) {
          auto p = Point(bx, by);
          if (b[p] == 1) {
            b[p] = 2;
            auto q = p+d;
            if (!b.valid(q) || b[q] != 1) continue loop;
            b[q] = 3;
          }
        }
      io.put!"{exit: true}"("YES");
    }
  }

  io.put("NO");
}

struct Point2(T)
{
  alias P = Point2!T, Op = string;
  T x, y;
  pure P opBinary(Op o)(P r) if (o=="+"||o=="-")
  { return mixin("P(x"~o~"r.x, y"~o~"r.y)"); }
  P opOpAssign(Op o)(P r) if (o=="+"||o=="-")
  { mixin("x"~o~"=r.x; y"~o~"=r.y;"); return this; }
  pure P opBinary(Op o)(T a) if (o=="*"||o=="/")
  { return mixin("P(x"~o~"a, y"~o~"a)"); }
  P opOpAssign(Op o)(T a) if (o=="*"||o=="/")
  { mixin("x"~o~"=a; y"~o~"=a;"); return this; }
  pure T opBinary(Op o: "*")(P r) { return x*r.x+y*r.y; }
  pure T hypot2() { return x^^2+y^^2; }
}

pure T distManhattan(T)(Point2!T p1, Point2!T p2)
{ return (p1.x-p2.x).abs + (p1.y-p2.y).abs; }

pure T cross(T)(Point2!T p1, Point2!T p2)
{ return p1.x*p2.y - p1.y*p2.x; }

struct Point3(T)
{
  alias P = Point3!T, Op = string;
  T x, y, z;
  pure P opBinary(Op o)(P r) if (o=="+"||o=="-")
  { return mixin("P(x"~o~"r.x, y"~o~"r.y, z"~o~"r.z)"); }
  P opOpAssign(Op o)(P r) if (o=="+"||o=="-")
  { mixin("x"~o~"=r.x; y"~o~"=r.y; z"~o~"=r.z;"); return this; }
  pure P opBinary(Op o)(T a) if (o=="*"||o=="/")
  { return mixin("P(x"~o~"a, y"~o~"a, z"~o~"a)"); }
  P opOpAssign(Op o)(T a) if (o=="*"||o=="/")
  { mixin("x"~o~"=a; y"~o~"=a; z"~o~"=a;"); return this; }
  pure T opBinary(Op o: "*")(P r) { return x*r.x+y*r.y+z*r.z; }
  pure T hypot2() { return x^^2+y^^2+z^^2; }
}

pure Point3!T cross(T)(Point3!T p1, Point3!T p2)
{ return Point3!T(p1.y*p2.z - p1.z*p2.y, p1.z*p2.x - p1.x*p2.z, p1.x*p2.y - p1.y*p2.x); }

struct Grid(T)
{
  alias G = Grid!T, P = Point2!int, Point = P;
  size_t c, r;
  T[][] data;

  this(size_t c, size_t r) { this.c = c; this.r = r; data = new T[][](r, c); }
  this(T[][] data) { c = data[0].length; r = data.length; this.data = data; }
  pure G dup() { return G(data.map!"a.dup".array); }

  pure P i2p(size_t i) { return P(cast(int)(i%c), cast(int)(i/c)); }
  pure size_t p2i(P p) { return p.x*c + p.y; }

  pure T opIndex(size_t x, size_t y) { return data[y][x]; }
  pure T opIndex(P p) { return data[p.y][p.x]; }
  G opIndexAssign(T v, size_t x, size_t y) { data[y][x] = v; return this; }
  G opIndexAssign(T v, P p) { data[p.y][p.x] = v; return this; }
  G opIndexOpAssign(string op)(T v, size_t x, size_t y)
  { mixin("data[y][x]"~op~"=v;"); return this; }
  G opIndexOpAssign(string op)(T v, P p)
  { mixin("data[p.y][p.x]"~op~"=v;"); return this; }
  G opIndexUnary(string op)(size_t x, size_t y) if (op=="++"||op=="--")
  { mixin(op~"data[y][x];"); return this; }
  G opIndexUnary(string op)(P p) if (op=="++"||op=="--")
  { mixin(op~"data[p.y][p.x];"); return this; }

  pure bool valid(size_t x, size_t y) { return 0 <= x && x < c && 0 <= y && y < r; }
  pure bool valid(P p) { return valid(p.x, p.y); }
  auto d4 = [P(-1, 0), P(0, -1), P(1, 0), P(0, 1)];
  pure auto around4(P p) { return d4.map!(d => d+p).filter!(np => valid(np)); }
  auto d8 = [P(-1, 0), P(-1, -1), P(0, -1), P(1, -1), P(1, 0), P(1, 1), P(0, 1), P(-1, 1)];
  pure auto around8(P p) { return d8.map!(d => d+p).filter!(np => valid(np)); }
}
Grid!T grid(T)(T[][] data) { return Grid!T(data); }

auto io = IO!()();
import std.stdio;
struct IO(alias IN = stdin, alias OUT = stdout)
{
  import std.conv, std.format, std.meta, std.traits, core.stdc.stdlib;

  auto getV(T...)(ref T v) { foreach (ref w; v) get(w); }
  auto getA(T)(size_t n, ref T v) if (hasAssignableElements!T)
  { v = new T(n); foreach (ref w; v) get(w); }
  auto 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]);
  }
  auto 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...)
  {
    auto getS(T)(size_t n, ref T v)
    { v = new T(n); foreach (ref w; v) foreach (e; E) mixin("get(w."~e~");"); }
  }

  auto put(alias conf = "{}", T...)(T v)
  { mixin("const PutConf c = "~conf~"; putMain!c(v);"); }
  auto putB(alias conf = "{}", S, T)(bool c, S t, T f)
  { if (c) put(t); else put(f); }
  auto 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; }
    auto get(T)(ref T v) { if (sp.empty) nextLine(); v = sp.front.to!T; sp.popFront(); }

    auto putMain(PutConf c, T...)(T v)
    {
      foreach (i, w; v) {
        putOne!c(w);
        if (i < v.length-1) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    auto putOne(PutConf c, T)(T v)
    {
      static if (isInputRange!T && !isSomeString!T) putRange!c(v);
      else if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else OUT.write(v);
    }
    auto putRange(PutConf c, T)(T v)
    {
      auto w = v;
      while (!w.empty) {
        putOne!c(w.front); w.popFront();
        if (!w.empty) OUT.write(c.delimiter);
      }
    }
  }
}
const struct PutConf
{
  bool newline = true, flush, exit;
  string floatFormat = "%.10f", delimiter = " ";
}
0