結果

問題 No.161 制限ジャンケン
ユーザー te-shte-sh
提出日時 2016-08-31 03:33:28
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2,343 ms / 5,000 ms
コード長 1,428 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 104,468 KB
実行使用メモリ 13,776 KB
最終ジャッジ日時 2023-09-02 21:43:50
合計ジャッジ時間 10,073 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
5,928 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2,343 ms
13,776 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2,342 ms
12,908 KB
testcase_09 AC 3 ms
4,368 KB
testcase_10 AC 184 ms
6,176 KB
testcase_11 AC 159 ms
6,172 KB
testcase_12 AC 87 ms
5,404 KB
testcase_13 AC 1,600 ms
6,988 KB
testcase_14 AC 299 ms
6,916 KB
testcase_15 AC 680 ms
6,736 KB
testcase_16 AC 150 ms
7,500 KB
testcase_17 AC 86 ms
5,164 KB
testcase_18 AC 114 ms
5,664 KB
権限があれば一括ダウンロードができます

ソースコード

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