結果

問題 No.1029 JJOOII 3
ユーザー ThistleThistle
提出日時 2020-03-27 13:51:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,077 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 166,632 KB
実行使用メモリ 199,616 KB
最終ジャッジ日時 2024-04-09 19:12:45
合計ジャッジ時間 4,632 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 3 ms
11,856 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 69 ms
193,108 KB
testcase_16 AC 73 ms
187,152 KB
testcase_17 AC 81 ms
187,568 KB
testcase_18 WA -
testcase_19 AC 5 ms
20,072 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 34 ms
173,964 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 3 ms
7,764 KB
testcase_38 WA -
testcase_39 AC 4 ms
15,960 KB
testcase_40 AC 4 ms
15,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma warning (disable: 4996)
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
const int maxN = 80;
const int maxK = 100000;
const int maxC = 1000000000;
string s[105];
int c[105], siz[105], cr[105][105][3];
int dp[3][102][100102];
int n, K;

void input() {
	cin >> n >> K;
	rep(i, n)cin >> s[i] >> c[i];
}

int solve() {
	input();

	rep(i, n) {
		siz[i] = s[i].size();
		rep(j, siz[i]) {
			if (s[i][j] == 'J')cr[i][j + 1][0]++;
			if (s[i][j] == 'O')cr[i][j + 1][1]++;
			if (s[i][j] == 'I')cr[i][j + 1][2]++;
		}
		rep(j, siz[i]) {
			rep(k, 3) {
				cr[i][j + 1][k] += cr[i][j][k];
			}
		}
	}

	rep(k, 3) {
		rep(i, n + 1)rep(j, K + 100)dp[k][i][j] = inf;
		dp[k][0][0] = 0;
		rep(i, n) {
			rep(j, K + 100) {
				dp[k][i + 1][j] = dp[k][i][j];
				int v = cr[i][siz[i]][k];
				if (j >= v)dp[k][i + 1][j] = min(dp[k][i + 1][j], dp[k][i + 1][j - v] + c[i]);
			}
		}

		for (int j = K + 90; j > 0; j--)dp[k][n][j - 1] = min(dp[k][n][j], dp[k][n][j - 1]);
		//		rep(j, K + 1)cout << dp[k][n][j] << ' '; cout << endl;
	}

	int ans = inf;

	//中央に1個使う

	rep(i, n) {
		if (cr[i][siz[i]][1] < K)continue;
		int res = c[i];
		rep(j, siz[i]) {
			for (int k = j; k < siz[i]; k++) {
				if (cr[i][k + 1][1] - cr[i][j][1] < K)continue;
				int cst = c[i];
				int J = cr[i][j][0], I = cr[i][siz[i]][2] - cr[i][k][2];
				if (J < K)cst += dp[0][n][K - J];
				if (I < K)cst += dp[2][n][K - I];
				ans = min(ans, cst);
			}
		}
	}

	//中央に2個使う
/*
	rep(i, n) {
		rep(j, n) {
			rep(k, siz[i] + 1) {
				rep(l, siz[j] + 1) {//~k-1][k~l-1][l~
					int cst = c[i] + c[j];
					int J = cr[i][k][0], O = cr[i][siz[i]][1] - cr[i][k][1] + cr[j][l][1], I = cr[j][siz[j]][2] - cr[j][l][2];
					if (J < K)cst += dp[0][n][K - J];
					if (O < K)cst += dp[1][n][K - O];
					if (I < K)cst += dp[2][n][K - I];
					ans = min(ans, cst);
				}
			}
		}
	}*/
	if (ans >= inf)ans = -1;
	return ans;
}


signed main() {
	cout << solve() << endl;
}
0