結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
HIR180
|
| 提出日時 | 2020-04-17 21:36:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,661 bytes |
| コンパイル時間 | 4,384 ms |
| コンパイル使用メモリ | 221,760 KB |
| 最終ジャッジ日時 | 2025-01-09 19:48:45 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 14 |
ソースコード
//Let's join Kaede Takagaki Fan Club !!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
rep(i,a.size()) cout << a[i] << " ";
cout << endl;
}
template<class T>
bool chmax(T&a, T b){
if(a < b){
a = b;
return 1;
}
return 0;
}
template<class T>
bool chmin(T&a, T b){
if(a > b){
a = b;
return 1;
}
return 0;
}
template<class T>
void g(T &a){
cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const int mod = 1000000007;
template<class T>
void add(T&a,T b){
a+=b;
if(a >= mod) a-=mod;
}
int n, kk;
string s[105];
int c[105];
ll dp[3][100005];
int main(){
ios::sync_with_stdio(false);
cin >> n >> kk;
repn(i, n) cin >> s[i] >> c[i];
rep(i, 3) rep(j, 100005) dp[i][j] = 1e18;
string sp = "JOI";
rep(x, 3){
dp[x][0] = 0;
repn(i, n){
int k = 0;
for(auto at:s[i]) k += (at == sp[x]);
rep(j, 100005){
if(j+k >= 100005) continue;
chmin(dp[x][j+k], dp[x][j] + c[i]);
}
}
}
//JO & OI & JOI
vector<P1>vec[2];
vector<P2>vv;
ll ans = 1e18;
repn(i, n){
rep(j, s[i].size()+1){
int a = 0, b = 0;
rep(k, j) a += (s[i][k] == 'J');
for(int k=j;k<s[i].size();k++) b += (s[i][k] == 'O');
vec[0].pb(mp(c[i], mp(a, b)));
a = 0, b = 0;
rep(k, j) a += (s[i][k] == 'O');
for(int k=j;k<s[i].size();k++) b += (s[i][k] == 'I');
vec[1].pb(mp(c[i], mp(a, b)));
for(int k=j;k<s[i].size()+1;k++) {
a = 0, b = 0;
int d = 0;
rep(aa, j) a += (s[i][aa] == 'J');
for(int bb=j;bb<k;bb++) b += (s[i][bb] == 'O');
for(int cc=k;cc<s[i].size();cc++) d += (s[i][cc] == 'I');
if(b >= kk){
chmin(ans, 1LL*c[i] + dp[0][max(0, kk-a)] + dp[2][max(0, kk-d)]);
}
}
}
}
for(auto at:vec[0]) for(auto at2:vec[1]){
int z1 = max(0, kk - at.sc.fi);
int z2 = max(0, kk - at.sc.sc - at2.sc.fi);
int z3 = max(0, kk - at2.sc.sc);
chmin(ans, 1LL*at.fi + at2.fi + dp[0][z1] + dp[1][z2] + dp[2][z3]);
}
if(ans > 5e17) ans = -1;
o(ans);
}
HIR180