結果

問題 No.1029 JJOOII 3
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2020-04-17 22:00:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,609 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 200,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 14:10:14
合計ジャッジ時間 6,191 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 2 ms
6,944 KB
testcase_38 WA -
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
string S[80]; int C[80];
ll dp[4][101010];
//---------------------------------------------------------------------------------------------------
string JOI = "JOI";
int joicnt[80][3];
pair<int, int> memo[3][81][80];
pair<int, int> get(int joi, int cnt, int i) {
	if (joicnt[i][joi] + cnt < K) return { joi, cnt + joicnt[i][joi] };
	if (0 <= memo[joi][K - cnt][i].first) return memo[joi][K - cnt][i];

	pair<int, int>& m = memo[joi][K - cnt][i];

	fore(c, S[i]) {
		if (JOI[joi] == c) {
			cnt++;
			if (cnt == K) {
				joi++;
				cnt = 0;
				if (joi == 3) return m = { 3, 0 };
			}
		}
	}

	return m = { joi, cnt };
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> S[i] >> C[i];

	rep(i, 0, N) fore(c, S[i]) rep(j, 0, 3) if (c == JOI[j]) joicnt[i][j]++;

	rep(joi, 0, 4) rep(cnt, 0, K + 1) dp[joi][cnt] = infl;
	dp[0][0] = 0;
	rep(joi, 0, 3) rep(cnt, 0, K + 1) rep(i, 0, N) memo[joi][cnt][i].first = -1;

	rep(joi, 0, 3) rep(cnt, 0, K) if(dp[joi][cnt] < infl) rep(i, 0, N) {
		int joi2, cnt2;
		tie(joi2, cnt2) = get(joi, cnt, i);
		chmin(dp[joi2][cnt2], dp[joi][cnt] + C[i]);
	}

	if (dp[3][0] == infl) cout << -1 << endl;
	else cout << dp[3][0] << endl;
}





0