QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#335063 | #6366. Message | ExplodingKonjac | WA | 79ms | 98260kb | C++20 | 6.0kb | 2024-02-22 16:55:38 | 2024-02-22 16:55:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OPENIOBUF
namespace FastIO
{
class FastIOBase
{
protected:
#ifdef OPENIOBUF
static const int BUFSIZE=1<<16;
char buf[BUFSIZE+1];
int buf_p=0;
#endif
FILE *target;
FastIOBase(FILE *f): target(f){}
~FastIOBase()=default;
public:
#ifdef OPENIOBUF
virtual void flush()=0;
#endif
};
class FastOutput final: public FastIOBase
{
public:
FastOutput(FILE *f=stdout): FastIOBase(f) {}
#ifdef OPENIOBUF
~FastOutput() { flush(); }
void flush() { fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
void put(char x)
{
#ifdef OPENIOBUF
if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
putc(x,target);
#endif
}
FastOutput &operator <<(char x)
{ return put(x),*this; }
FastOutput &operator <<(const char *s)
{ for(;*s;put(*(s++)));return *this; }
FastOutput &operator <<(const std::string &s)
{ return (*this)<<s.c_str(); }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastOutput&> operator <<(T x)
{
if(x<0) return put('-'),(*this)<<(-x);
char stk[std::numeric_limits<T>::digits10+1],*top=stk;
do *(top++)=x%10+'0',x/=10; while(x);
while(top!=stk) put(*(--top));
return *this;
}
template<typename ...T>
void writesp(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put(' '),0)...}; }
template<typename ...T>
void writeln(T &&...x)
{ std::initializer_list<int>{((*this)<<(x),put('\n'),0)...}; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> writesp(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<' '; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> writeln(Iter begin,Iter end)
{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;
class FastInput final: public FastIOBase
{
private:
bool __eof;
public:
FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
{ buf_p=BUFSIZE; }
void flush() { buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
bool eof()const { return buf[buf_p]==EOF; }
#else
{}
bool eof()const { return feof(target); }
#endif
char get()
{
if(__eof) return EOF;
#ifdef OPENIOBUF
if(buf_p==BUFSIZE) flush();
char ch=buf[buf_p++];
#else
char ch=getc(target);
#endif
return ~ch?ch:(__eof=true,EOF);
}
void unget(char c)
{
__eof=false;
#ifdef OPENIOBUF
buf[--buf_p]=c;
#else
ungetc(c,target);
#endif
}
explicit operator bool()const { return !__eof; }
FastInput &operator >>(char &x)
{ while(isspace(x=get()));return *this; }
template<typename T>
std::enable_if_t<std::is_integral<T>::value,FastInput&> operator >>(T &x)
{
char ch,sym=0;x=0;
while(isspace(ch=get()));
if(__eof) return *this;
if(ch=='-') sym=1,ch=get();
for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=get());
return unget(ch),sym?x=-x:x,*this;
}
FastInput &operator >>(char *s)
{
while(isspace(*s=get()));
if(__eof) return *this;
for(;!isspace(*s) && !__eof;*(++s)=get());
return unget(*s),*s='\0',*this;
}
FastInput &operator >>(std::string &s)
{
char str_buf[(1<<8)+1]={0},*p=str_buf;
char *const buf_end=str_buf+(1<<8);
while(isspace(*p=get()));
if(__eof) return *this;
for(s.clear(),p++;;p=str_buf)
{
for(;p!=buf_end && !isspace(*p=get()) && !__eof;p++);
if(p!=buf_end) break;
s.append(str_buf);
}
unget(*p),*p='\0',s.append(str_buf);
return *this;
}
template<typename ...T>
void read(T &&...x)
{ std::initializer_list<int>{((*this)>>(x),0)...}; }
template<typename Iter>
std::enable_if_t<std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iter>::iterator_category>
::value> read(Iter begin,Iter end)
{ while(begin!=end) (*this)>>*(begin++); }
}qin;
} // namespace FastIO
using FastIO::qin,FastIO::qout;
using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;
constexpr LL INF=4e18;
#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#define LOG(...) [](auto...){}(__VA_ARGS__)
#else
#define FILEIO(file)
#define LOG(...) fprintf(stderr,__VA_ARGS__)
#endif
constexpr int MAXN=2e5;
char s1[MAXN+5],s2[MAXN+5],s3[MAXN+5];
int n,m,a[MAXN+5];
int tot,pos[60],nxt[MAXN+5];
LL dp[60][MAXN+5],sum[MAXN+5];
int main()
{
qin>>(s1+1)>>(s2+1);
n=strlen(s1+1);
m=strlen(s2+1);
qin.read(a+1,a+n+1);
int lb[26],rb[26];
for(int i=0;i<26;i++) lb[i]=m+1,rb[i]=0;
for(int i=1;i<=m;i++)
{
int c=s2[i]-'a';
lb[c]=min(lb[c],i);
rb[c]=max(rb[c],i);
}
for(int i=0;i<26;i++)
{
if(lb[i]>rb[i]) continue;
pos[++tot]=lb[i];
pos[++tot]=rb[i]+1;
}
sort(pos+1,pos+tot+1);
tot=unique(pos+1,pos+tot+1)-pos-1;
for(int k=0;k<tot;k++) fill(dp[k],dp[k]+n+1,INF);
dp[0][0]=0;
for(int i=1;i<=n;i++) dp[0][i]=dp[0][i-1]+a[i];
for(int k=1;k<tot;k++)
{
int len=pos[k+1]-pos[k];
char *s3=s2+pos[k]-1;
bool vis[26]={};
for(int i=0;i<26;i++) vis[i]=(lb[i]<=k && rb[i]>=k);
nxt[1]=0;
for(int i=2,j=0;i<=len;i++)
{
while(j && s3[i]!=s3[j+1]) j=nxt[j];
if(s3[i]==s3[j+1]) j++;
nxt[i]=j;
}
vector<pair<int,LL>> vec;
LL mn=dp[k-1][0];
for(int i=1;i<=n;i++)
{
sum[i]=sum[i-1]+(vis[s1[i]-'a']?0:a[i]);
if(vis[s1[i]-'a'])
vec.emplace_back(i,mn),mn=INF;
mn=min(mn,dp[k-1][i]-sum[i]);
}
vec.emplace_back(n+1,mn);
for(int i=0,j=0;i+1<(int)vec.size();i++)
{
int p=vec[i].first;
while(j && (j==len || s1[p]!=s3[j+1])) j=nxt[j];
if(s1[p]==s3[j+1]) j++;
if(j==len)
{
LL val=vec[i-len+1].second;
for(;p<vec[i+1].first;p++)
dp[k][p]=min(dp[k][p],val+sum[p]);
}
}
}
LL ans=INF,sum=0;
for(int i=n;i>=1;i--)
ans=min(ans,dp[tot-1][i]+sum),sum+=a[i];
if(ans<INF) qout<<ans<<'\n';
else qout<<"You better start from scratch man...\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11752kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 2ms
memory: 14080kb
input:
babab baab 2 1 3 2 4
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #3:
score: 0
Accepted
time: 19ms
memory: 24396kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #4:
score: 0
Accepted
time: 38ms
memory: 35056kb
input:
bdabcfbdfcffebebcabbadacbbaeeaffbdedeedfabefdfdbddcecdaaddafdfbbdceccedebcecdfbcfbaafcefeecffdabfaacbeeecfeffaaafaefdcdaaeaeecfafcdadbfbccbdecacfeabdbfcacafebdcfbfbebacbffaecbfbcedccabbdecabaebbbdbcfbaeadfcadfadfaebaddbebfcbefdabdcefbbdaaaabcefedabcabcafedcfadedfdcbbccbffdcfdfcfcdfcfbbdabdbbeecafecc...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #5:
score: 0
Accepted
time: 79ms
memory: 98260kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #6:
score: -100
Wrong Answer
time: 15ms
memory: 21948kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
You better start from scratch man...
result:
wrong answer 1st lines differ - expected: '0', found: 'You better start from scratch man...'