QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718559#2517. Critical Structuresyuto1115#RE 0ms0kbC++201.4kb2024-11-06 20:50:572024-11-06 20:51:07

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 20:51:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-06 20:50:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep2(i,j,k) for(ll i = ll(j); i < ll(k); i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i = ll(j)-1; i >= ll(k); i--)
#define rrep(i,k) rrep2(i,k,0)
#define all(a) a.begin(), a.end()
#define SZ(a) ll(a.size())
#define eb emplace_back
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
const ll inf = LLONG_MAX/4;
bool chmin(auto& a, auto b) {return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, auto b) {return a < b ? a = b, 1 : 0; }

int main(){
	cin.tie(0)->sync_with_stdio(0);
	string s; cin >> s;
	ll n = SZ(s);
	ll m; cin >> m;
	string t = "RGBCMYK";
	vl a(n);
	rep(i,n){
		rep(j,SZ(t)){
			if(s[i] == t[j]) a[i] = j;
		}
	}
	ll d = SZ(t);
	vector<vvl> dp(n+1, vvl(n+1, vl(d, -inf)));	
        rep(i,n+1) dp[i][i] = vl(d, 0);
	rep2(w,1,n+1){
		rep(l,n){
			ll r = l+w;
			if(r > n) break;
			rep2(i,l+1,r){
				rep(j,d) chmax(dp[l][r][j], dp[l][i][j] + dp[i][r][j]);
			}
			chmax(dp[l][r][a[l]], dp[l+1][r][a[l]]+1);
			chmax(dp[l][r][a[r-1]], dp[l][r-1][a[r-1]]+1);
			bool flag = false;
			rep(j,d){
				if(dp[l][r][d] >= m){
					flag = true;
				}
			}
			rep(j,d){
				if(flag) chmax(dp[l][r][j], 0ll);
			}
		}
	}
	cout << dp[2][n][0] << endl;
	bool flag = false;
	rep(j,d){
		if(dp[0][n][j] >= m || dp[0][n][j] == 0) flag = true;
	}
	string ans = "No";
	if(flag) ans = "Yes";
	cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

1
6 6
1 2
2 3
3 4
4 5
5 6
6 1

output:


result: