結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
leaf_1415
|
| 提出日時 | 2020-04-17 22:38:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 668 ms / 2,000 ms |
| コード長 | 2,236 bytes |
| コンパイル時間 | 784 ms |
| コンパイル使用メモリ | 82,652 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-10-03 14:19:02 |
| 合計ジャッジ時間 | 12,927 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
using namespace std;
typedef pair<llint, llint> P;
llint n, k;
string s[85];
llint S[85];
llint c[85];
llint dp[300005];
llint sum[85][3][85];
llint pos[85][85][3][85];
llint trans(llint p, llint id)
{
llint v = 0;
while(p < 3*k && v < S[id]){
llint type = p/k, num = (p+k)/k*k - p;
if(num > S[id] || pos[id][v+1][type][num] > inf/2){
p += sum[id][type][S[id]] - sum[id][type][v];
return p;
}
p += num;
v = pos[id][v+1][type][num];
}
return p;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> s[i] >> c[i];
S[i] = s[i].size();
for(int j = 0; j < S[i]; j++){
if(s[i][j] == 'J') s[i][j] = '0';
if(s[i][j] == 'O') s[i][j] = '1';
if(s[i][j] == 'I') s[i][j] = '2';
}
s[i] = "#" + s[i];
}
for(int i = 1; i <= n; i++){
for(int k = 1; k <= S[i]; k++){
for(int j = 0; j < 3; j++) sum[i][j][k] = sum[i][j][k-1];
sum[i][s[i][k]-'0'][k]++;
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= S[i]; j++){
for(int k = 0; k < 3; k++){
for(int l = 0; l <= S[i]; l++) pos[i][j][k][l] = inf;
llint cnt = 0;
for(int l = j; l <= S[i]; l++){
if(s[i][l]-'0' == k){
cnt++;
pos[i][j][k][cnt] = l;
}
}
}
}
}
/*for(int i = 0; i < 3*k; i++){
for(int j = 1; j <= n; j++){
cout << trans(i, j) << " ";
}
cout << endl;
}*/
for(int i = 1; i <= 3*k; i++) dp[i] = inf;
for(int i = 0; i < 3*k; i++){
for(int j = 1; j <= n; j++){
chmin(dp[trans(i, j)], dp[i] + c[j]);
}
}
//for(int i = 0; i <= 3*k; i++) cout << dp[i] << " "; cout << endl;
if(dp[3*k] > inf/2) cout << -1 << endl;
else cout << dp[3*k] << endl;
return 0;
}
leaf_1415