結果

問題 No.2076 Concon Substrings (ConVersion)
ユーザー 沙耶花
提出日時 2022-09-16 22:06:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,914 ms / 5,000 ms
コード長 894 bytes
コンパイル時間 4,498 ms
コンパイル使用メモリ 252,360 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 00:38:36
合計ジャッジ時間 15,272 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001




int main(){
	
	int N,A,B;
	cin>>N>>A>>B;
	
	string s;
	cin>>s;
	
	vector<int> t(1,0);
	rep(i,s.size()){
		while(s.substr(i,3)=="con"){
			t.back()++;
			i += 3;
		}
		t.push_back(0);
	}
	
	vector<int> dp(N+1,-Inf32);
	dp[0] = 0;
	rep(i,t.size()){
		if(t[i]==0)continue;
		vector<int> ndp(N+1,-Inf32);
		rep(j,N+1){
			if(dp[j]==-Inf32)continue;
			rep(k,t[i]/A+1){
				if(j+k>N)break;
				ndp[j+k] = max(ndp[j+k],dp[j] + (t[i]-k*A)/B);
			}
		}
		swap(dp,ndp);
	}
	
	int ans = 0;
	rep(i,N+1){
		if(dp[i]==-Inf32)continue;
		int x = i,y = dp[i];
		if(x>y+1)x = y+1;
		if(y>x)y = x;
		ans = max(ans,x+y);
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0