結果

問題 No.1029 JJOOII 3
ユーザー theory_and_metheory_and_me
提出日時 2020-04-19 15:43:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 2,355 bytes
コンパイル時間 2,708 ms
コンパイル使用メモリ 208,584 KB
実行使用メモリ 6,116 KB
最終ジャッジ日時 2024-04-15 14:53:57
合計ジャッジ時間 6,790 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 29 ms
5,376 KB
testcase_05 AC 136 ms
5,724 KB
testcase_06 AC 98 ms
5,376 KB
testcase_07 AC 124 ms
5,504 KB
testcase_08 AC 131 ms
5,596 KB
testcase_09 AC 115 ms
5,376 KB
testcase_10 AC 122 ms
5,504 KB
testcase_11 AC 141 ms
5,980 KB
testcase_12 AC 77 ms
5,376 KB
testcase_13 AC 152 ms
5,984 KB
testcase_14 AC 148 ms
5,976 KB
testcase_15 AC 96 ms
5,376 KB
testcase_16 AC 103 ms
5,504 KB
testcase_17 AC 133 ms
5,984 KB
testcase_18 AC 134 ms
5,980 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 165 ms
6,112 KB
testcase_33 AC 158 ms
6,116 KB
testcase_34 AC 157 ms
5,984 KB
testcase_35 AC 159 ms
6,112 KB
testcase_36 AC 165 ms
5,988 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 <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

ll cum[100][3];
vector<char> moji = {'J', 'O', 'I'};
map<char, int> jimo;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    jimo['J'] = 0;
    jimo['O'] = 1;
    jimo['I'] = 2;

    ll N, K;
    cin >> N >> K;
    vector<string> S(N);
    vector<ll> C(N);
    REP(i, N) cin >> S[i] >> C[i];

    string T = "";
    REP(i, K) T += 'J';
    REP(i, K) T += 'O';
    REP(i, K) T += 'I';
    
    const ll INF = (1ll<<60);
    vector<ll> dp(3*K+1, INF);
    dp[0] = 0;

    REP(i, N){
        REP(j, 3){
            REP(k, S[i].size()){
                if(S[i][k] == moji[j]) cum[i][j]++;   
            }
        }
    }

    REP(i, 3*K){
        REP(j, N){
            if(T[i] == T[i+81]){
                chmin(dp[i+cum[j][jimo[T[i]]]], dp[i] + C[j]);
            }else{
                int pos = i;
                REP(k, S[j].size()){
                    if(pos < 3*K and S[j][k] == T[pos]){
                        pos++;
                    }
                    chmin(dp[pos], dp[i] + C[j]);
                }
            }
        }
    }

    cout << (dp[3*K] == INF ? -1 : dp[3*K]) << endl;

    return 0;
}
0