結果

問題 No.161 制限ジャンケン
ユーザー kk
提出日時 2020-07-03 21:09:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,075 bytes
コンパイル時間 2,678 ms
コンパイル使用メモリ 203,364 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-15 04:02:28
合計ジャッジ時間 3,461 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 19 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 29 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 6 ms
4,352 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 23 ms
4,352 KB
testcase_14 AC 6 ms
4,352 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int calc(vector<int> &me, vector<int> &you) {
  int ret = 0;
  REP (i, me.size()) {
    if ((me[i] + 1) % 3 == you[i])
      ret += 3;
    else if (me[i] == you[i])
      ++ret;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  vector<int> me, you;

  REP (i, 3) {
    int c;
    cin >> c;
    REP (j, c) me.push_back(i);
  }

  string t;
  cin >> t;
  for (char c: t)
    you.push_back(string("GCP").find(c));

  bool update = true;
  int ret = calc(me, you);
  while (update) {
    update = false;
    REP (i, me.size()) REP (j, i) {
      if (me[i] != me[j]) {
        swap(me[i], me[j]);
        int tmp = calc(me, you);
        if (tmp > ret) {
          ret = tmp;
          update = true;
        } else {
          swap(me[i], me[j]);
        }
      }
    }
  }

  cout << calc(me, you) << endl;
  
  return 0;
}
0