結果

問題 No.2553 Holidays
ユーザー dyktr_06dyktr_06
提出日時 2023-11-18 01:42:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,708 bytes
コンパイル時間 4,346 ms
コンパイル使用メモリ 215,528 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-11-25 12:30:11
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 187 ms
8,064 KB
testcase_02 AC 188 ms
8,064 KB
testcase_03 AC 162 ms
8,064 KB
testcase_04 WA -
testcase_05 AC 165 ms
8,064 KB
testcase_06 WA -
testcase_07 AC 166 ms
8,064 KB
testcase_08 AC 135 ms
8,064 KB
testcase_09 AC 211 ms
8,064 KB
testcase_10 AC 81 ms
8,064 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 81 ms
8,064 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 155 ms
8,064 KB
testcase_20 AC 131 ms
8,064 KB
testcase_21 AC 151 ms
8,064 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 120 ms
8,320 KB
testcase_25 AC 30 ms
8,320 KB
testcase_26 AC 30 ms
8,320 KB
testcase_27 AC 30 ms
8,320 KB
testcase_28 AC 32 ms
8,320 KB
testcase_29 AC 30 ms
8,320 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 1 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 1 ms
6,548 KB
testcase_39 AC 1 ms
6,548 KB
testcase_40 AC 2 ms
6,548 KB
testcase_41 AC 2 ms
6,548 KB
testcase_42 WA -
testcase_43 AC 2 ms
6,548 KB
testcase_44 AC 2 ms
6,548 KB
testcase_45 AC 2 ms
6,548 KB
testcase_46 AC 2 ms
6,548 KB
testcase_47 AC 1 ms
6,548 KB
testcase_48 AC 2 ms
6,548 KB
testcase_49 AC 2 ms
6,548 KB
testcase_50 AC 2 ms
6,548 KB
testcase_51 AC 2 ms
6,548 KB
testcase_52 AC 1 ms
6,548 KB
testcase_53 WA -
testcase_54 AC 2 ms
6,548 KB
testcase_55 AC 2 ms
6,548 KB
testcase_56 AC 1 ms
6,548 KB
testcase_57 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;
    string s; cin >> s;
    assert(3 <= n && n <= 100000);
    assert(0 <= m && m <= n);

    // o---o, o--**, **--o が得できそう
    auto weight = [&](string &t){
        if(t == "o---o"){
            return 2;
        }
        if(t.substr(0, 3) == "o--" || t.substr(2, 3) == "--o"){
            return 1;
        }
        if(t.substr(1, 3) == "o-o"){
            return -1;
        }
        if(t[2] == '-'){
            return 0;
        }
        return -2;
    };

    map<string, set<int>> cnt;
    set<pair<int, int>> pq;

    auto get = [&](int i){
        string t = "";
        for(int j = i - 2; j <= i + 2; j++){
            if(0 <= j && j < n){
                t += s[j];
            }else{
                t += "x";
            }
        }
        return weight(t);
    };
    auto update = [&](int i, char c){
        for(int j = i - 2; j <= i + 2; j++){
            if(0 <= j && j < n){
                pq.erase({get(j), j});
            }
        }

        s[i] = c;
        
        for(int j = i - 2; j <= i + 2; j++){
            if(0 <= j && j < n){
                pq.insert({get(j), j});
            }
        }
    };

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'o') ans++;
        pq.insert({get(i), i});
    }

    int can_op = m;
    while(can_op > 0 && !pq.empty()){
        auto [w, idx] = *(--pq.end());
        if(w <= -2) break;
        can_op--, ans++;
        update(idx, 'o');
    }
    for(auto [w, idx] : pq){
        if(w == -1){
            ans++;
        }
    }
    cout << ans << endl;
}
0