結果

問題 No.1029 JJOOII 3
ユーザー 👑 jupirojupiro
提出日時 2020-04-19 15:56:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 1,838 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 122,220 KB
実行使用メモリ 6,460 KB
最終ジャッジ日時 2024-04-15 15:09:14
合計ジャッジ時間 7,104 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 54 ms
5,484 KB
testcase_05 AC 249 ms
5,900 KB
testcase_06 AC 176 ms
5,376 KB
testcase_07 AC 222 ms
5,668 KB
testcase_08 AC 237 ms
5,824 KB
testcase_09 AC 204 ms
5,376 KB
testcase_10 AC 216 ms
5,660 KB
testcase_11 AC 265 ms
6,272 KB
testcase_12 AC 145 ms
5,376 KB
testcase_13 AC 269 ms
6,152 KB
testcase_14 AC 273 ms
6,020 KB
testcase_15 AC 182 ms
5,376 KB
testcase_16 AC 210 ms
5,788 KB
testcase_17 AC 251 ms
6,000 KB
testcase_18 AC 253 ms
6,140 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 291 ms
6,308 KB
testcase_33 AC 292 ms
6,184 KB
testcase_34 AC 290 ms
6,340 KB
testcase_35 AC 294 ms
6,460 KB
testcase_36 AC 291 ms
6,312 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N, K; cin >> N >> K;
	vector<string> vs(N);
	vector<ll> cost(N);
	for (int i = 0; i < N; i++) cin >> vs[i] >> cost[i];
	vector<vector<ll>> cnt(N, vector<ll>(3));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < vs[i].size(); j++) {
			if (vs[i][j] == 'J') cnt[i][0]++;
			if (vs[i][j] == 'O') cnt[i][1]++;
			if (vs[i][j] == 'I') cnt[i][2]++;
		}
	}
	string t;
	t += string(K, 'J') + string(K, 'O') + string(K, 'I') + string(100, '#');
	vector<ll> dp(3 * K + 500, INF);
	dp[0] = 0;
	for (int i = 0; i < 3 * K; i++) {
		for (int j = 0; j < N; j++) {
			int pos = i;
			if (t[i] == t[i + 80]) {
				pos += cnt[j][i / K];
			}
			else {
				for (int k = 0; k < vs[j].size(); k++) {
					if (t[pos] == vs[j][k]) pos++;
				}
			}
			chmin(dp[pos], dp[i] + cost[j]);
		}

	}
	if (dp[3 * K] == INF) dp[3 * K] = -1;
	cout << dp[3 * K] << endl;
	return 0;
}
0