結果

問題 No.1029 JJOOII 3
ユーザー 沙耶花沙耶花
提出日時 2020-04-17 22:25:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 2,583 ms
コンパイル使用メモリ 206,216 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 14:41:37
合計ジャッジ時間 5,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 8 ms
6,944 KB
testcase_04 AC 22 ms
6,944 KB
testcase_05 AC 96 ms
6,944 KB
testcase_06 AC 69 ms
6,940 KB
testcase_07 AC 85 ms
6,944 KB
testcase_08 AC 90 ms
6,944 KB
testcase_09 AC 79 ms
6,944 KB
testcase_10 AC 83 ms
6,944 KB
testcase_11 AC 103 ms
6,940 KB
testcase_12 AC 57 ms
6,944 KB
testcase_13 AC 103 ms
6,940 KB
testcase_14 AC 105 ms
6,944 KB
testcase_15 AC 71 ms
6,940 KB
testcase_16 AC 82 ms
6,944 KB
testcase_17 AC 96 ms
6,944 KB
testcase_18 AC 99 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 3 ms
6,948 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 110 ms
6,944 KB
testcase_33 AC 110 ms
6,944 KB
testcase_34 AC 111 ms
6,944 KB
testcase_35 AC 111 ms
6,940 KB
testcase_36 AC 110 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000000


int main() {
	
	int N,K;
	cin>>N>>K;
	
	vector<long long> dp(3*K+1,Inf);
	
	vector<string> S(N);
	vector<long long> C(N);
	
	for(int i=0;i<N;i++)cin>>S[i]>>C[i];
	
	vector<vector<vector<int>>> ind(3,vector<vector<int>>(N,vector<int>()));
	
	for(int i=0;i<N;i++){
		for(int j=0;j<S[i].size();j++){
			if(S[i][j]=='J')ind[0][i].push_back(j);
			else if(S[i][j]=='O')ind[1][i].push_back(j);
			else ind[2][i].push_back(j);
		}
	}
	
	dp[0] = 0;
	
	for(int i=0;i<3*K;i++){
		int x = i/K;
		for(int j=0;j<N;j++){
			int to = min(3*K,i + (int)ind[x][j].size());
			if(to/K==x){
				dp[to] = min(dp[to],dp[i]+C[j]);
			}
			else{
				int now = 0;
				to = i;
				while(true){
					//cout<<now<<endl;
					auto it= lower_bound(ind[to/K][j].begin(),ind[to/K][j].end(),now);
					if(it==ind[to/K][j].end())break;
					now = *it;
					now++;
					to++;
					dp[to] = min(dp[to],dp[i]+C[j]);
					if(to==3*K)break;
				}
			}
		}
	}
	
	if(dp.back()==Inf)cout<<-1<<endl;
	else cout<<dp.back()<<endl;
	
    return 0;
}
0