結果

問題 No.2553 Holidays
ユーザー dyktr_06
提出日時 2023-11-18 01:58:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,814 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 207,820 KB
最終ジャッジ日時 2025-02-17 22:26:55
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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