結果

問題 No.1029 JJOOII 3
ユーザー IKyoproIKyopro
提出日時 2020-04-17 23:31:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,429 bytes
コンパイル時間 2,954 ms
コンパイル使用メモリ 207,316 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 15:41:38
合計ジャッジ時間 18,326 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 546 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 700 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 644 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 534 ms
6,944 KB
testcase_16 AC 646 ms
6,940 KB
testcase_17 AC 751 ms
6,940 KB
testcase_18 AC 772 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 3 ms
6,940 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 820 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 3 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:26:5: warning: control reaches end of non-void function [-Wreturn-type]
   26 |     };
      |     ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template <class T> using vvvec = vector<vvec<T>>;
template <class T> using vvvvec = vector<vvvec<T>>;

void chmin(ll &a,ll b){if(a>b) a = b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<string> S(N);
    vec<int> C(N);
    vvec<int> cnt(N,vec<int>(3));
    vvvec<int> pos(N,vvec<int>(81,vec<int>(3)));

    auto id = [](char c){
        if(c=='J') return 0;
        if(c=='O') return 1;
        if(c=='I') return 2;
    };

    for(int i=0;i<N;i++){
        cin >> S[i] >> C[i];
        for(auto& c:S[i]){
            cnt[i][id(c)]++;
        }
        int n = S[i].size();
        for(int j=0;j<n;j++){
            int ord = 1;
            for(int k=j-1;k>=0;k--) if(S[i][j]==S[i][k]) ord++;
            pos[i][ord][id(S[i][j])] = j;
        }
    }
    ll inf = 1e18;
    vec<ll> dp(3*K+1,inf);
    dp[0] = 0;
    for(int i=0;i<3*K;i++) for(int j=0;j<N;j++){
        if(i<K){
            if(i+cnt[j][0]<K){
                chmin(dp[i+cnt[j][0]],dp[i]+C[j]);                
            }else{
                int n = pos[j][cnt[j][0]][0];
                int now = n;
                int c = 0;
                for(int k=n+1;k<S[j].size();k++){
                    c += (S[j][k]=='O');
                    now = k;
                    if(c==K){
                        break;
                    }
                }
                if(c<K){
                    chmin(dp[K+c],dp[i]+C[j]);   
                }else{
                    c = 0;
                    for(int k=now+1;k<S[j].size();k++) c += (S[j][k]=='I');
                    chmin(dp[min(3*K,2*K+c)],dp[i]+C[j]);
                }
            }
        }else if(i<2*K){
            if(i+cnt[j][1]<2*K){
                chmin(dp[i+cnt[j][1]],dp[i]+C[j]);             
            }else{
                int n = pos[j][cnt[j][1]][1];
                int c = 0;
                for(int k=n+1;k<S[j].size();k++) c += (S[j][k]=='I');
                chmin(dp[min(3*K,2*K+c)],dp[i]+C[j]);
            }
        }else{
            chmin(dp[min(3*K,i+cnt[j][2])],dp[i]+C[j]);
        }
    }
    for(int i=0;i<=3*K;i++) cerr << dp[i] << (i!=3*K? " ":"\n");
    cout << (dp[3*K]!=inf? dp[3*K]:-1) << "\n";
}
0