結果

問題 No.2553 Holidays
ユーザー dyktr_06dyktr_06
提出日時 2023-11-18 01:58:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,814 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 215,760 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-11-25 12:30:14
合計ジャッジ時間 6,940 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 145 ms
8,320 KB
testcase_02 AC 145 ms
8,320 KB
testcase_03 AC 146 ms
8,320 KB
testcase_04 WA -
testcase_05 AC 146 ms
8,320 KB
testcase_06 WA -
testcase_07 AC 145 ms
8,320 KB
testcase_08 AC 147 ms
8,320 KB
testcase_09 AC 147 ms
8,320 KB
testcase_10 AC 96 ms
8,320 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 96 ms
8,320 KB
testcase_14 AC 90 ms
8,064 KB
testcase_15 WA -
testcase_16 AC 151 ms
8,064 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 153 ms
8,320 KB
testcase_20 AC 135 ms
8,320 KB
testcase_21 AC 135 ms
8,320 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 137 ms
8,320 KB
testcase_25 AC 36 ms
8,320 KB
testcase_26 AC 37 ms
8,320 KB
testcase_27 AC 36 ms
8,320 KB
testcase_28 AC 38 ms
8,320 KB
testcase_29 AC 36 ms
8,320 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 2 ms
6,548 KB
testcase_41 AC 2 ms
6,548 KB
testcase_42 AC 2 ms
6,548 KB
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 2 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 2 ms
6,548 KB
testcase_53 AC 2 ms
6,548 KB
testcase_54 AC 2 ms
6,548 KB
testcase_55 AC 2 ms
6,548 KB
testcase_56 AC 2 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-x" || t.substr(1, 3) == "x-o"){
            return -1;
        }
        if(t.substr(1, 3) == "o-o"){
            return -2;
        }
        if(t[2] == '-'){
            return 0;
        }
        return -3;
    };

    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 == -2){ // *o-o*
            ans++;
        }
    }
    cout << ans << endl;
}
0