結果
問題 |
No.2553 Holidays
|
ユーザー |
|
提出日時 | 2023-11-18 01:42:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,708 bytes |
コンパイル時間 | 2,188 ms |
コンパイル使用メモリ | 206,016 KB |
最終ジャッジ日時 | 2025-02-17 22:26:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 WA * 14 |
ソースコード
#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; }