結果

問題 No.714 回転寿司屋のシミュレート
ユーザー te-sh
提出日時 2018-07-24 10:39:51
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 102,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-13 01:31:59
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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 pickV(R,T...)(ref R r,ref T t){foreach(ref v;t)pick(r,v);}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);

  int[string] h;
  auto neta(string s)
  {
    if (s !in h) h[s] = h.length.to!int;
    return h[s];
  }

  auto ns = 20, nn = 53;
  auto l = new int[][](ns, nn);

  auto find(string s)
  {
    auto u = neta(s);
    foreach (i; 0..ns)
      if (l[i][u]) {
        --l[i][u];
        return i;
      }
    return -2;
  }

  foreach (_; 0..n) {
    auto rd = rdsp;
    int t; pick(rd, t);

    switch (t) {
    case 0:
      int ni, mi; pickV(rd, ni, mi); --ni;
      foreach (_2; 0..mi) {
        string a; pickV(rd, a);
        ++l[ni][neta(a)];
      }
      break;
    case 1:
      string b; pickV(rd, b);
      writeln(find(b)+1);
      break;
    case 2:
      int c; pickV(rd, c); --c;
      l[c][] = 0;
      break;
    default:
      assert(0);
    }
  }
}
0