Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
51523 AK2022071320 最优子序列 C++ 解答错误 0 7 MS 292 KB 2355 2022-07-13 11:50:28

Tests(0/20):


#include <bits/stdc++.h> using namespace std; int n,k,type; string a; int d; int ai[5100]; //int d; int num; int countn[510]; int frome; int bto; int ans=0; int maxn; int minn; int minn2; int main() { //freopen ("seq.in","r",stdin);// //freopen ("seq.out","w",stdout );// cin>>n>>k>>type; cin>>a; d=a[n-1]; num=n-1; for (int i=n-2; i>=0; i--) { //d=a[i-1]-'A'+1; //ai[d]++; if (a[i]==d) { //cout<<1<<" "<<endl;//<<a[i] countn[i]=-1; countn[num]++; } else { //cout<<1<<" "<<endl; d=a[i]; num=i;; } } // }for (int i=1;i<=k;i++){ // if (a[i]!=0 && a[i]!=1) { // for (int j=1;j<=n;j++){ // if (char(i+'A'-1)==a[j] && (j==1 || a[])) // } // } // } for (int i=0; i<=n-1; i++) { for (int j=0; j<=n-1; j++) { // || ; if (a[j]==a[i] && countn[j]!=-1 && countn[i]!=-1 &&i!=j) { maxn=max(i,j); minn=min(i,j); if ( max(i,j)-countn[max(i,j)]-1-min(i,j)<min(countn[i],countn[j] )+1) { for (int k=min(i,j)+1; k<=max(i,j)-1; k++) { countn[k]=-1; } continue; } if ( max(i,j)-countn[max(i,j)]-1-min(i,j) ==min(countn[i],countn[j] )+1 ) { if (countn[maxn]> countn[minn] && a[maxn-countn[maxn]-1]>a[maxn] || countn[maxn]< countn[minn] && a[minn+1]>a[minn]) for (int k=min(i,j)+1; k<=max(i,j)-1; k++) { countn[k]=-1; } continue; } if (countn[i]>countn[j]) { countn[j]=-1; } else if (countn[i]<countn[j]) { countn[i]=-1; } else { if (a[i]<a[i+1]) countn[j]=-1; else countn[i]=-1; } } } } // for (int i=1; i<=n; i++) // { // cout<<countn[i-1]<<" "; // } // cout<<endl; for (int i=1; i<=n; i++) { if (countn[i-1]!=-1) { ans+=countn[i-1]+1; //cout<<a[i-1]; } } cout<<ans<<endl;;// if (type!=0) for (int i=1; i<=n; i++) { if (countn[i-1]!=-1) { //ans++;+i for (int j=1; j<=countn[i-1]+1; j++) cout<<a[i-1]; } } return 0; }


测评信息: