QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#332338#6366. MessagexcyyyyyCompile Error//C++144.1kb2024-02-19 14:35:252024-02-19 14:35:25

Judging History

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

  • [2024-02-19 14:35:25]
  • 评测
  • [2024-02-19 14:35:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define SN 200005
int N,n,m,c[SN];
char s[SN],t[SN];

int num;
int vis[200];
pair<int,int> x[60];
unsigned int C,X;int nxt[SN],S[SN],T[SN],lc[SN];
ll f[SN][60],pre[SN];
vector<int> G;
int main(){
    srand(time(0));
    scanf("%s%s",s+1,t+1);N=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=N;i++)scanf("%d",&c[i]);

    memset(vis,0,sizeof(vis));
    for(int i=1;i<=m;i++)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
    memset(vis,0,sizeof(vis));
    for(int i=m;i;i--)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
    sort(x+1,x+1+num);num=unique(x+1,x+1+num)-x-1;

    memset(f,-0x3f,sizeof(f));
    for(int i=0;i<=N;i++)f[i][0]=0;
    x[num+1].first=m+1;
    for(int j=1;j<=num;j++){
        n=m=C=0;
        for(int i=0;i<26;i++){
            bool f=false,g=false;
            for(int k=1;k<=j;k++)f|=x[k].second==j+'a';
            for(int k=j+1;k<=num;k++)g|=x[k].second==j+'a';
            C|=(f&&g)<<i;
        }
        X=C;
        C|=1<<(x[j].second-'a');T[++m]=x[j].second;
        for(int i=x[j].first+1;i<x[j+1].first;i++)T[++m]+=t[i];
        for(int i=1;i<=N;i++)if(C>>(s[i]-'a')&1)S[++n]=s[i],lc[n]=i,pre[n]=c[i]+pre[n-1]; 
        for(int i=2,j=0;i<=n;nxt[i++]=(T[j]==T[i]))
            while(j&&T[j]!=T[i])j=nxt[j];
        for(int i=1,k=0;i<=n;i++){
            while(k&&T[k+1]!=S[i])k=nxt[k];
            k+=T[k+1]==S[i];
            if(k==m)f[lc[i]][j]=max(f[lc[i]][j],f[lc[i-m+1]-1][j-1]+pre[i]-pre[i-m]);
        }
        for(int i=1;i<=N;i++)if(~X>>(s[i]-'a')&1)f[i][j]=max(f[i][j],f[i-1][j]);
    }
    
    if(f[N][num]<0)return puts("You better start from scratch man..."),0;
    f[N][num]=-f[N][num];
    for(int i=1;i<=N;i++)f[N][num]+=c[i];
    printf("%lld\n",f[N][num]);
}#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
int n,m,c[N];
char s[N],t[N];

int num;
int vis[200];
pair<int,int> x[60];char a[60];
int v[60][26],b[60][26];

ll f[N][60];int cnt[60];
vector<int> G;
int main(){
    srand(time(0));
    scanf("%s%s",s+1,t+1);n=strlen(s+1),m=strlen(t+1);
    for(int i=1;i<=n;i++)scanf("%d",&c[i]);

    memset(vis,0,sizeof(vis));
    for(int i=1;i<=m;i++)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
    memset(vis,0,sizeof(vis));
    for(int i=m;i;i--)if(!vis[t[i]])vis[t[i]]=1,x[++num]={i,t[i]};
    sort(x+1,x+1+num);num=unique(x+1,x+1+num)-x-1;

    x[num+1].first=m+1;
    for(int i=1;i<=num;i++){
        a[i]=x[i].second;
        for(int j=x[i].first+1;j<x[i+1].first;j++)
            ++v[i][t[j]-'a'];
        for(int j=0;j<26;j++){
            bool f=false,g=false;
            for(int k=1;k<=i;k++)f|=x[k].second==j+'a';
            for(int k=i+1;k<=num;k++)g|=x[k].second==j+'a';
            if(!f||!g)v[i][j]=n+1;
        }
    }
    memset(f,-0x3f,sizeof(f));
    for(int i=0;i<=n;i++)f[i][0]=0;
    for(int j=1;j<=num;j++){//转移第 j 段
        memset(cnt,0,sizeof(cnt));int gd=0,all=0;ll w=0;
        for(int i=0;i<26;i++)gd+=v[j][i]==0,all+=v[j][i]!=n+1;
        for(int i=0,r=0;i<n;i++){//printf("Case %d \n",i);
            gd-=v[j][s[i+1]-'a']!=n+1&&cnt[s[i+1]-'a']==v[j][s[i+1]-'a'];
            --cnt[s[i+1]-'a'];
            w-=(v[j][s[i+1]-'a']!=n+1)*c[i+1];
            //printf("del %d %c | ",i+1,s[i+1]);
            //puts("");
            while(r<n&&(gd!=all&&cnt[s[r+1]-'a']+1<=v[j][s[r+1]-'a']||r<i+1)){
                ++r;
                ++cnt[s[r]-'a'];
                //printf("add %d %c | ",r,s[r]);
                w+=(v[j][s[r]-'a']!=n+1)*c[r];
                gd+=v[j][s[r]-'a']!=n+1&&cnt[s[r]-'a']==v[j][s[r]-'a'];
            }//puts("");
            //printf("%d %d %d\n",gd,all,r);
            //for(int i=0;i<26;i++)cout<<cnt[i]<<" ";puts("");
            if(s[i+1]==a[j]&&gd==all)f[r][j]=max(f[i][j-1]+w+c[i+1],f[r][j]);
        }
        for(int i=1;i<=n;i++)if(v[j][s[i]-'a']==n+1)f[i][j]=max(f[i][j],f[i-1][j]);
    }
    if(f[n][num]<0)return puts("You better start from scratch man..."),0;
    f[n][num]=-f[n][num];
    for(int i=1;i<=n;i++)f[n][num]+=c[i];
    printf("%lld\n",f[n][num]);
}

详细

answer.code:54:2: error: stray ‘#’ in program
   54 | }#include<bits/stdc++.h>
      |  ^
answer.code:54:3: error: ‘include’ does not name a type
   54 | }#include<bits/stdc++.h>
      |   ^~~~~~~
answer.code:58:5: error: redefinition of ‘int n’
   58 | int n,m,c[N];
      |     ^
answer.code:5:7: note: ‘int n’ previously declared here
    5 | int N,n,m,c[SN];
      |       ^
answer.code:58:7: error: redefinition of ‘int m’
   58 | int n,m,c[N];
      |       ^
answer.code:5:9: note: ‘int m’ previously declared here
    5 | int N,n,m,c[SN];
      |         ^
answer.code:58:9: error: redefinition of ‘int c [200005]’
   58 | int n,m,c[N];
      |         ^
answer.code:5:11: note: ‘int c [200005]’ previously declared here
    5 | int N,n,m,c[SN];
      |           ^
answer.code:59:6: error: redefinition of ‘char s [200005]’
   59 | char s[N],t[N];
      |      ^
answer.code:6:6: note: ‘char s [200005]’ previously declared here
    6 | char s[SN],t[SN];
      |      ^
answer.code:59:11: error: redefinition of ‘char t [200005]’
   59 | char s[N],t[N];
      |           ^
answer.code:6:12: note: ‘char t [200005]’ previously declared here
    6 | char s[SN],t[SN];
      |            ^
answer.code:61:5: error: redefinition of ‘int num’
   61 | int num;
      |     ^~~
answer.code:8:5: note: ‘int num’ previously declared here
    8 | int num;
      |     ^~~
answer.code:62:5: error: redefinition of ‘int vis [200]’
   62 | int vis[200];
      |     ^~~
answer.code:9:5: note: ‘int vis [200]’ previously declared here
    9 | int vis[200];
      |     ^~~
answer.code:63:15: error: redefinition of ‘std::pair<int, int> x [60]’
   63 | pair<int,int> x[60];char a[60];
      |               ^
answer.code:10:15: note: ‘std::pair<int, int> x [60]’ previously defined here
   10 | pair<int,int> x[60];
      |               ^
answer.code:66:4: error: redefinition of ‘long long int f [200005][60]’
   66 | ll f[N][60];int cnt[60];
      |    ^
answer.code:12:4: note: ‘long long int f [200005][60]’ previously declared here
   12 | ll f[SN][60],pre[SN];
      |    ^
answer.code:67:13: error: redefinition of ‘std::vector<int> G’
   67 | vector<int> G;
      |             ^
answer.code:13:13: note: ‘std::vector<int> G’ previously declared here
   13 | vector<int> G;
      |             ^
answer.code:68:5: error: redefinition of ‘int main()’
   68 | int main(){
      |     ^~~~
answer.code:14:5: note: ‘int main()’ previously defined here
   14 | int main(){
      |     ^~~~
answer.code: In function ‘int main()’:
answer.code:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     scanf("%s%s",s+1,t+1);N=strlen(s+1),m=strlen(t+1);
      |     ~~~~~^~~~~~~~~~~~~~~~
answer.code:17:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     for(int i=1;i<=N;i++)scanf("%d",&c[i]);
      |                          ~~~~~^~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:70:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   70 |     scanf("%s%s",s+1,t+1);n=strlen(s+1),m=strlen(t+1);
      |     ~~~~~^~~~~~~~~~~~~~~~
answer.code:71:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   71 |     for(int i=1;i<=n;i++)scanf("%d",&c[i]);
      |                          ~~~~~^~~~~~~~~~~~