Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
51563 zengjilin 最优子序列 C++ 解答错误 0 0 MS 280 KB 775 2022-07-13 11:52:54

Tests(0/20):


#include <bits/stdc++.h> using namespace std; int c1[26]; int n,k,type; struct lo { char c; int count=1; } l[3005]; int main() { scanf("%d %d %d",&n,&k,&type); int t=n; for(int i=1; i<=t; i++) { cin>>l[i].c; if(l[i-1].c==l[i].c) { l[i-1].count++; i--,t--; } } for(int i=96; i<=96+k; i++) { for(int j=1; j<=t; j++) { if((char)i==l[j].c&&l[j].count>c1[i-95]) c1[i-95]=l[j].count; } } long long sum=0; for(int i=1; i<=k; i++) sum+=c1[i]; if(type==0) printf("%lld\n",sum); else if(type==1||type==2) { printf("%lld\n",sum); for(int i=96; i<=96+k; i++) { for(int j=1; j<=c1[i-95]; j++) cout<<(char)i; } cout<<endl; } return 0; }


测评信息: