結果

問題 No.1029 JJOOII 3
ユーザー 沙耶花沙耶花
提出日時 2020-04-17 22:25:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 2,229 ms
コンパイル使用メモリ 210,904 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-07-27 01:17:38
合計ジャッジ時間 5,612 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,384 KB
testcase_04 AC 23 ms
4,620 KB
testcase_05 AC 97 ms
5,288 KB
testcase_06 AC 70 ms
4,912 KB
testcase_07 AC 86 ms
4,824 KB
testcase_08 AC 91 ms
5,164 KB
testcase_09 AC 80 ms
4,924 KB
testcase_10 AC 83 ms
5,148 KB
testcase_11 AC 102 ms
5,428 KB
testcase_12 AC 58 ms
4,380 KB
testcase_13 AC 103 ms
5,732 KB
testcase_14 AC 105 ms
5,480 KB
testcase_15 AC 71 ms
4,608 KB
testcase_16 AC 83 ms
4,956 KB
testcase_17 AC 96 ms
5,080 KB
testcase_18 AC 99 ms
5,436 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,384 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 110 ms
5,360 KB
testcase_33 AC 110 ms
5,728 KB
testcase_34 AC 110 ms
5,368 KB
testcase_35 AC 109 ms
5,424 KB
testcase_36 AC 110 ms
5,472 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 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