QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393211#6366. MessageCharlieVinnieCompile Error//C++236.7kb2024-04-18 12:04:012024-04-18 12:04:01

Judging History

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

  • [2024-04-18 12:04:01]
  • 评测
  • [2024-04-18 12:04:01]
  • 提交

answer

#include "bits/stdc++.h"
#undef DEBUG
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](){}()
#define debuga(...) [](){}()
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=2e5+5;
char S[N],T[N],a[N],b[N]; int n,m,acnt,bcnt,posa[N],nxt[N],to[N][30],Xsum[N],Ysum[N],Xpos[N],Ypos[N],vis[26],V,cmp[30][30]; ll w[N];
int ban[N],beg[N]; ll val[N],f[N],tmp[N];
inline void ckmin(int& x,int y) { x=min(x,y); }
inline void ckmax(int& x,int y) { x=max(x,y); }
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
    if(n<m) return cout<<"-1\n",0;
    For(i,1,m) if(!vis[T[i]-'a']) vis[T[i]-'a']=++V;
    debug(vis);
    For(x,0,25) if(vis[x]) For(y,x+1,25) if(vis[y]) {
        acnt=bcnt=0;
        For(i,1,n) if(S[i]=='a'+x||S[i]=='a'+y) a[++acnt]=S[i],posa[acnt]=i;
        For(i,1,m) if(T[i]=='a'+x||T[i]=='a'+y) b[++bcnt]=T[i];
        int Xcnt=0,Ycnt=0;
        For(i,1,acnt){
            if(a[i]=='a'+x){
                Xpos[Xsum[i]=++Xcnt]=i; Ysum[i]=Ycnt;
            }
            else{
                Ypos[Ysum[i]=++Ycnt]=i; Xsum[i]=Xcnt;
            }
        }
        int L=1; while(b[L+1]==b[L]) L++;
        int R=bcnt; while(b[R-1]==b[R]) R--;
        L++; R--;
        if(L>R){
            int u=(b[1]=='a'+x?x:y);
            int v=(b[bcnt]=='a'+x?x:y);
            assert(u!=v);
            cmp[vis[u]][vis[v]]=1;
            cmp[vis[v]][vis[u]]=-1;
            For(i,1,acnt){
                if(a[i]=='a'+v){
                    if(v==y){
                        if(Ysum[i]<bcnt-R) continue;
                        int t=Ypos[Ysum[i]-(bcnt-R)+1];
                        if(Xsum[t-1]<R) continue;
                        int o=Xpos[Xsum[t-1]];
                        to[posa[i]][vis[x]]=posa[o];
                    }
                    else{
                        if(Xsum[i]<bcnt-R) continue;
                        int t=Xpos[Xsum[i]-(bcnt-R)+1];
                        if(Ysum[t-1]<R) continue;
                        int o=Ypos[Ysum[t-1]];
                        to[posa[i]][vis[y]]=posa[o];
                    }
                }
            }
            continue;
        }
        bool oth=0; For(i,L,R) if(b[i]!=b[L]) { oth=1; break; }
        if(!oth){
            if(b[L]=='a'+x){
                cmp[vis[y]][vis[x]]=-1;
            }
            else{
                cmp[vis[x]][vis[y]]=-1;
            }
        }
        nxt[L]=L-1;
        for(int i=L+1,j=L-1;i<=R;i++){
            while(j>=L&&b[j+1]!=b[i]) j=nxt[j];
            if(b[j+1]==b[i]) j++;
            nxt[i]=j;
        }
        for(int i=1,j=L-1;i<=acnt;i++){
            while(j>=L&&b[j+1]!=a[i]) j=nxt[j];
            if(b[j+1]==a[i]) j++;
            if(j==R){
                j=nxt[j];
                if(a[i]=='a'+x){
                    if( (b[1]=='a'+x?Xsum[i-(R-L+1)]:Ysum[i-(R-L+1)])>=L-1 && Ysum[acnt]-Ysum[i]>=bcnt-R ){
                        int u = Ypos[Ysum[i]+(bcnt-R)]; to[posa[u]][vis[x]]=posa[i]; to[posa[i]][vis[y]]=posa[u];
                    }
                }
                else{
                    if( (b[1]=='a'+x?Xsum[i-(R-L+1)]:Ysum[i-(R-L+1)])>=L-1 && Xsum[acnt]-Xsum[i]>=bcnt-R ){
                        int u = Xpos[Xsum[i]+(bcnt-R)]; to[posa[u]][vis[y]]=posa[i]; to[posa[i]][vis[x]]=posa[u];
                    }
                }
            }
        }
    }
    // For(u,1,V){
    //     int lst=0;
    //     For(i,1,n) if(vis[S[i]-'a']==u) {
    //         if(lst==0) { lst=i; continue; }
    //         For(v,1,V) if(cmp[u][v]==1) to[i][v]=max(to[i][v],to[lst][v]);
    //         lst=i;
    //     }
    //     lst=0;
    //     Rev(i,n,1) if(vis[S[i]-'a']==u) {
    //         if(lst==0) { lst=i; continue; }
    //         For(v,1,V) if(cmp[u][v]==-1) to[i][v]=min(to[i][v],to[lst][v]);
    //         lst=i;
    //     }
    // }
    For(i,1,V) debuga(cmp[i],1,V);
    For(u,1,n){
        For(i,1,V) if(vis[S[u]-'a']!=i) debug(u,i,to[u][i]);
    }
    For(x,1,V){
        int L=0,R=0;
        For(i,1,m) if(vis[T[i]-'a']==x) R=i;
        Rev(i,m,1) if(vis[T[i]-'a']==x) L=i;
        For(i,L,R-1) ban[i]=1;
        int cntB=0; For(i,1,m) if(vis[T[i]-'a']==x) cntB++;
        static int pos[N]; int pcnt=0; ll qwq=0;
        For(i,1,n) if(vis[S[i]-'a']==x){
            qwq+=w[i]; pos[++pcnt]=i;
            if(pcnt>=cntB) qwq-=w[pos[pcnt-cntB]],val[i]=qwq,beg[i]=pos[pcnt-cntB+1];
            else val[i]=-1e18;
        }
    }
    debuga(val,1,n);
    f[0]=0; For(i,1,n) f[i]=-1e18;
    int has[30]={0};
    auto work=[&](){
        For(i,0,n) tmp[i]=f[i],f[i]=-1e18;
        For(i,1,n) tmp[i]=max(tmp[i],tmp[i-1]);
        int qwq=0;
        For(u,1,V) if(has[u]){
            int ok=1;
            For(v,1,V) if(has[v]&&cmp[u][v]!=0) { ok=0; break; }
            if(ok) { qwq=u; break; }
        }
        debug(qwq);
        assert(qwq);
        For(i,1,n) if(vis[S[i]-'a']==qwq) {
            int pos[30]={0};
            function<bool(int,int)> dfs=[&](int u,int o){
                if(pos[u]) return pos[u]==o?true:false;
                else pos[u]=o;
                For(v,1,V) if(v!=u&&cmp[u][v]==0){
                    if(to[o][v]==0) return false;
                    if(!dfs(v,to[o][v])) return false;
                }
                return true;
            };
            if(!dfs(qwq,i)) continue;
            For(u,1,V) if(has[u]) assert(pos[u]);
            int OK=1; For(u,1,V) if(has[u]) For(v,1,V) if(has[v]){
                if(cmp[u][v]==1&&pos[u]>to[pos[v]][u]) { OK=0; goto OUT; }
            }
            OUT: if(!OK) continue;
            int mx=0,mn=1e9; For(u,1,V) if(has[u]) mx=max(mx,pos[u]),mn=min(mn,beg[pos[u]]);
            if(mn==0) continue;
            ll tt=0; For(u,1,V) { tt+=val[pos[u]]; if(tt<-1e18) break; }
            f[mx]=max(f[mx],tmp[mn-1]+tt);
        }
    };
    debuga(ban,1,m);
    For(i,1,m){
        has[vis[T[i]-'a']]=1;
        if(!ban[i]){
            work(); memset(has,0,sizeof(has));
            debug(i); debuga(f,0,n);
        }
    }
    ll ans=-1e18; For(i,1,n) ans=max(ans,f[i]);
    if(ans<0) cout<<"-1\n";
    else{
        ans=-ans; For(i,1,n) ans+=w[i];
        cout<<ans<<'\n';
    }
    return 0;
}

// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING

// Started Coding On: April 18 Thu, 07 : 48 : 39

Details

answer.code: In function ‘int main()’:
answer.code:22:8: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’)
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |     ~~~^~~~~~~
      |     |      |
      |     |      char*
      |     std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from answer.code:1:
/usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  325 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/13/istream:325:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: cannot bind non-const lvalue reference of type ‘void*&’ to an rvalue of type ‘void*’
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |          ~~^~~
/usr/include/c++/13/istream:201:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  201 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:201:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: invalid conversion from ‘char*’ to ‘long long unsigned int’ [-fpermissive]
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |          ~~^~~
      |            |
      |            char*
answer.code:22:12: error: cannot bind rvalue ‘(long long unsigned int)(((char*)(& S)) + 1)’ to ‘long long unsigned int&’
/usr/include/c++/13/istream:197:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  197 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:197:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: invalid conversion from ‘char*’ to ‘long long int’ [-fpermissive]
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |          ~~^~~
      |            |
      |            char*
answer.code:22:12: error: cannot bind rvalue ‘(long long int)(((char*)(& S)) + 1)’ to ‘long long int&’
/usr/include/c++/13/istream:192:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:192:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: invalid conversion from ‘char*’ to ‘long unsigned int’ [-fpermissive]
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |          ~~^~~
      |            |
      |            char*
answer.code:22:12: error: cannot bind rvalue ‘(long unsigned int)(((char*)(& S)) + 1)’ to ‘long unsigned int&’
/usr/include/c++/13/istream:188:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:188:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: invalid conversion from ‘char*’ to ‘long int’ [-fpermissive]
   22 |     cin>>(S+1)>>(T+1); n=strlen(S+1); m=strlen(T+1); For(i,1,n) cin>>w[i];
      |          ~~^~~
      |            |
      |            char*
answer.code:22:12: error: cannot bind rvalue ‘(long int)(((char*)(& S)) + 1)’ to ‘long int&’
/usr/include/c++/13/istream:184:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:184:7: note:   conversion of argument 1 would be ill-formed:
answer.code:22:12: error: invalid conversion from ‘char*’ to ‘unsigned int’ [-fpermissive]
   22 | ...