結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,676 KB
testcase_01 AC 6 ms
6,676 KB
testcase_02 AC 6 ms
6,676 KB
testcase_03 AC 5 ms
6,676 KB
testcase_04 AC 6 ms
6,676 KB
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 5 ms
6,676 KB
testcase_09 AC 4 ms
6,676 KB
testcase_10 AC 6 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 6 ms
6,676 KB
testcase_14 AC 6 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
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 AC 5 ms
6,676 KB
testcase_23 AC 5 ms
6,676 KB
testcase_24 AC 5 ms
6,676 KB
testcase_25 AC 5 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 5 ms
6,676 KB
testcase_28 AC 6 ms
6,676 KB
testcase_29 AC 5 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 1 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 3 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 28 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 1 ms
6,676 KB
testcase_44 AC 1 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 1 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 1 ms
6,676 KB
testcase_50 AC 1 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 2 ms
6,676 KB
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 2 ms
6,676 KB
testcase_56 AC 1 ms
6,676 KB
testcase_57 AC 2 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;
		}
		if(a==0&&b==0){
			return x>y;
		}
		return a>b;
	});
	int tef=0;
	for(auto[t,nm]:vv){
		if(t==2){
			while(m>0&&nm>=2){
				m--;
				ans+=2;
				nm-=2;
			}
			if(nm==1) ans++;
		}else if(t==1){
			while(m>0&&nm>=2){
				m--;
				ans+=2;
				nm-=2;
			}
			if(nm==1) tef++;
		}else{
			if(m>0){
				m--;
				ans++;
				nm--;
				while(m>0&&nm>=2){
					m--;
					ans+=2;
					nm-=2;
				}
				if(nm==1) tef++;
			}
		}
	}
	ans+=min(tef,m);
	cout<<ans<<endl;
}
0