結果
| 問題 |
No.2553 Holidays
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-08 00:14:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,222 bytes |
| コンパイル時間 | 2,316 ms |
| コンパイル使用メモリ | 205,736 KB |
| 最終ジャッジ日時 | 2025-02-18 09:11:15 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 WA * 24 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
int n,m;
string s;
cin>>n>>m>>s;
vector<pair<char,int>> vp;
int ans=0;
{
char bf=s.at(0);
int nm=0;
for(char c:s){
if(c=='o') ans++;
if(bf==c) nm++;
else{
vp.push_back({bf,nm});
bf=c;
nm=1;
}
}
vp.push_back({bf,nm});
}
vector<pair<int,int>> vv;
rep(i,vp.size()){
if(vp.at(i).first=='-'){
int ct=0;
if(vp.at(i-1).first=='o') ct++;
if(vp.at(i+1).first=='o') ct++;
if(ct==2&&vp.at(i).second==1){
ans++;
continue;
}
vv.push_back({ct,vp.at(i).second});
}
}
sort(vv.begin(),vv.end(),[&](auto p,auto q){
auto[a,x]=p;
auto[b,y]=q;
if(a==2&&b==2){
if(x%2==1&&y%2==1){
return x<y;
}
return x%2>y%2;
}
return a>b;
});
int tef=0;
for(auto[t,nm]:vv){
if(t==2){
while(m&&nm>=2){
m--;
ans+=2;
nm-=2;
}
if(nm) ans++;
}else if(t==1){
while(m&&nm>=2){
m--;
ans+=2;
nm-=2;
}
if(nm) tef++;
}else{
if(m){
m--;
ans++;
nm--;
while(m&&nm>=2){
m--;
ans+=2;
nm-=2;
}
if(nm) tef++;
}
}
}
ans+=min(tef,m);
cout<<ans<<endl;
}