結果

問題 No.1005 BOT対策
ユーザー te-sh
提出日時 2020-03-27 02:56:21
言語 D
(dmd 2.091.0)
結果
AC  
実行時間 2 ms
コード長 2,802 Byte
コンパイル時間 615 ms
使用メモリ 8,948 KB
最終ジャッジ日時 2020-03-27 02:56:25

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample01 AC 1 ms
6,900 KB
00_sample02 AC 2 ms
6,896 KB
00_sample03 AC 1 ms
6,900 KB
01_small01 AC 2 ms
8,900 KB
01_small02 AC 2 ms
8,940 KB
01_small03 AC 2 ms
8,944 KB
01_small04 AC 1 ms
8,944 KB
01_small05 AC 2 ms
8,948 KB
01_small06 AC 1 ms
8,944 KB
01_small07 AC 2 ms
8,940 KB
01_small08 AC 2 ms
6,896 KB
01_small09 AC 2 ms
8,896 KB
01_small10 AC 1 ms
6,900 KB
02_large01 AC 2 ms
8,944 KB
02_large02 AC 2 ms
8,900 KB
02_large03 AC 2 ms
6,896 KB
02_large04 AC 1 ms
6,900 KB
02_large05 AC 2 ms
6,904 KB
02_large06 AC 2 ms
8,944 KB
02_large07 AC 1 ms
6,900 KB
02_large08 AC 1 ms
6,900 KB
02_large09 AC 2 ms
6,896 KB
02_large10 AC 2 ms
8,944 KB
02_large11 AC 1 ms
8,940 KB
02_large12 AC 1 ms
6,896 KB
02_large13 AC 2 ms
8,900 KB
02_large14 AC 1 ms
6,900 KB
02_large15 AC 1 ms
8,940 KB
02_large16 AC 2 ms
6,900 KB
99_challenge01.txt AC 1 ms
6,896 KB
テストケース一括ダウンロード

ソースコード

diff #
// URL: https://yukicoder.me/problems/no/1005

import std.algorithm, std.array, std.bitmanip, std.container, std.conv, std.format,
       std.functional, std.math, std.range, std.traits, std.typecons, std.stdio, std.string;

version(unittest) {} else
void main()
{
  string s; io.getV(s);
  string t; io.getV(t);

  int calc(string s, string t)
  {
    auto i = s.indexOf(t);
    if (i == -1) return 0;
    if (t.length == 1) return -1;
    return calc(s[i+t.length-1..$], t) + 1;
  }

  io.put(calc(s, t));
}

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

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

  const struct PutConf
  {
    bool newline = true, flush, exit;
    string floatFormat = "%.10f", delimiter = " ";
  }

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

    void putMain(PutConf c, T...)(T v)
    {
      foreach (i, w; v) {
        putOne!c(w);
        if (i+1 < v.length) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    void putOne(PutConf c, T)(T v)
    {
      static if (isInputRange!T && !isSomeString!T) putRange!c(v);
      else static if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else static if (hasMember!(T, "fprint")) v.fprint(OUT);
      else OUT.write(v);
    }
    void 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);
      }
    }
  }
}
0