結果

問題 No.640 76本のトロンボーン
ユーザー te-shte-sh
提出日時 2018-04-20 11:53:40
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,095 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 107,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 20:02:41
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

const r = r"^\.+$";

void main()
{
  int n; readV(n);
  string[] s; readC(n, s);

  auto t = s.dup.transposed.map!(array).array;
  auto r1 = max(calc11(n, s), calc12(n, s), calc21(n, s), calc22(n, s), calc3(n, s));
  auto r2 = max(calc11(n, t), calc12(n, t), calc21(n, t), calc22(n, t), calc3(n, t));
  auto r3 = calc4(n, s, t);

  writeln(max(r1, r2, r3));
}

auto canPut(R)(R s)
{
  return s.all!(c => c == '.');
}

auto calc11(R)(int n, R s)
{
  if (!s[0].take(n-1).canPut) return 0;
  auto t = 1;
  foreach (i; 0..n-1)
    if (s.transversal(i).drop(1).canPut) ++t;
  if (s.transversal(n-1).take(n-1).canPut || s.transversal(n-1).drop(1).canPut) ++t;
  return t;
}

auto calc12(R)(int n, R s)
{
  if (!s[0].drop(1).canPut) return 0;
  auto t = 1;
  foreach (i; 1..n)
    if (s.transversal(i).drop(1).canPut) ++t;
  if (s.transversal(0).take(n-1).canPut || s.transversal(0).drop(1).canPut) ++t;
  return t;
}

auto calc21(R)(int n, R s)
{
  if (!s[$-1].take(n-1).canPut) return 0;
  auto t = 1;
  foreach (i; 0..n-1)
    if (s.transversal(i).take(n-1).canPut) ++t;
  if (s.transversal(n-1).take(n-1).canPut || s.transversal(n-1).drop(1).canPut) ++t;
  return t;
}

auto calc22(R)(int n, R s)
{
  if (!s[$-1].drop(1).canPut) return 0;
  auto t = 1;
  foreach (i; 1..n)
    if (s.transversal(i).take(n-1).canPut) ++t;
  if (s.transversal(0).take(n-1).canPut || s.transversal(0).drop(1).canPut) ++t;
  return t;
}

auto calc3(R)(int n, R s)
{
  auto t = 0;
  foreach (i; 0..n)
    if (s.transversal(i).take(n-1).canPut || s.transversal(i).drop(1).canPut) ++t;
  return t;
}

auto calc4(R1, R2)(int n, R1 s, R2 t)
{
  return s[0].canPut && s[$-1].canPut && t[0].canPut && t[$-1].canPut ? 4 : 0;
}
0