結果

問題 No.2553 Holidays
ユーザー cho435cho435
提出日時 2023-12-08 00:14:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 213,764 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-08 00:14:56
合計ジャッジ時間 4,330 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0