結果

問題 No.161 制限ジャンケン
ユーザー te-sh
提出日時 2016-08-31 03:33:28
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2,459 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 116,612 KB
実行使用メモリ 12,512 KB
最終ジャッジ日時 2024-06-12 03:58:56
合計ジャッジ時間 10,582 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.bitmanip, std.random;
import std.string, std.conv, std.stdio, std.typecons;

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

  int[int[3]] memo;
  memo[[g, c, p]] = 0;

  foreach (t; s) {
    int[int[3]] memo2;
    foreach (gcp, a; memo) {
      if (gcp[0] > 0) {
        int[3] key = [gcp[0] - 1, gcp[1], gcp[2]];
        auto sc = score('G', t);
        memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc;
      }
      if (gcp[1] > 0) {
        int[3] key = [gcp[0], gcp[1] - 1, gcp[2]];
        auto sc = score('C', t);
        memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc;
      }
      if (gcp[2] > 0) {
        int[3] key = [gcp[0], gcp[1], gcp[2] - 1];
        auto sc = score('P', t);
        memo2[key] = key in memo2 ? max(memo2[key], a + sc) : a + sc;
      }
    }
    memo = memo2;
  }

  writeln(memo[[0, 0, 0]]);
}

int score(char s, char o)
{
  final switch (s) {
  case 'G':
    final switch (o) {
    case 'G': return 1;
    case 'C': return 3;
    case 'P': return 0;
    }
  case 'C':
    final switch (o) {
    case 'G': return 0;
    case 'C': return 1;
    case 'P': return 3;
    }
  case 'P':
    final switch (o) {
    case 'G': return 3;
    case 'C': return 0;
    case 'P': return 1;
    }
  }
}
0