結果

問題 No.161 制限ジャンケン
ユーザー te-sh
提出日時 2017-02-06 15:11:36
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 670 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 102,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-12 06:53:58
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap

void main()
{
  auto rd = readln.split.to!(int[]), g = rd[0], c = rd[1], p = rd[2];
  auto s = readln.chomp;

  auto fg = 0, fc = 0, fp = 0;
  foreach (f; s) {
    switch (f) {
    case 'G': ++fg; break;
    case 'C': ++fc; break;
    case 'P': ++fp; break;
    default: assert(0);
    }
  }

  auto r = 0;
  int a;

  a = min(g, fc); g -= a; fc -= a; r += a * 3;
  a = min(c, fp); c -= a; fp -= a; r += a * 3;
  a = min(p, fg); p -= a; fg -= a; r += a * 3;
  a = min(g, fg); r += a;
  a = min(c, fc); r += a;
  a = min(p, fp); r += a;

  writeln(r);
}
0