QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#526045 | #6366. Message | chenxinyang2006 | WA | 198ms | 239652kb | C++20 | 4.1kb | 2024-08-21 10:18:23 | 2024-08-21 10:18:23 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,m;
char _s[200005],_t[200005];
int w[200005];
int occ[2][26],delta[200005];
int sz,k,top,req,_len[60],_bas[60],_occ[60];
char s[60][200005],t[200005];
int nxt[200005],idx[200005],res[200005],fail[200005];//s 匹配 t 的哪些区间
ll cst[60][200005];
int ch[60][200005];
int sum[200005];
ll _sum[200005];
void slv(int p){
/* printf("slv p=%d\n",p);
rep(i,1,_len[p]) printf("%c",s[p][i]);
printf("\n");
rep(i,1,k) printf("%c",t[i]);
printf("\n");*/
int j = 0;
rep(i,2,_len[p]){
while(j && s[p][j + 1] != s[p][i]) j = fail[j];
if(s[p][j + 1] == s[p][i]) j++;
fail[i] = j;
}
j = 0;
rep(i,1,k){
while(j && s[p][j + 1] != t[i]) j = fail[j];
if(s[p][j + 1] == t[i]) j++;
res[i] = 0;
if(j == _len[p]){
res[i - _len[p] + 1] = 1;
j = fail[j];
}
}
/* rep(i,1,k) printf("%d",res[i]);
printf("\n");*/
top = req = 0;
rep(i,1,n){
sum[i] = sum[i - 1];
if(_s[i] == _occ[p]){
_sum[++top] = w[i];
sum[i]++;
}
}
rep(i,1,top) _sum[i] += _sum[i - 1];
// rep(i,1,top) printf("%lld ",_sum[i]);
// printf("\n");
rep(i,1,m) if(_t[i] == _occ[p]) req++;
// printf("req=%d\n",req);
rep(i,1,n){
if(nxt[i] > k || !res[nxt[i]]){
cst[p][i] = linf;
continue;
}
cst[p][i] = 0;
ch[p][i] = idx[nxt[i] + _len[p] - 1];
// printf("%d->%d ",i,ch[p][i]);
if(!_occ[p]) continue;
if(sum[i - 1] + req > top) cst[p][i] = linf;
else cst[p][i] = _sum[sum[i - 1]] + _sum[top] - _sum[sum[i - 1] + req];
}
// printf("\n");
/* rep(i,1,n) printf("%d ",nxt[i]);
printf("\n");
rep(i,1,n) printf("(%d,%lld) ",ch[p][i],cst[p][i]);
printf("\n");*/
}
ll dp[60][200005];
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
scanf("%s",_s + 1);
scanf("%s",_t + 1);
n = strlen(_s + 1);m = strlen(_t + 1);
rep(c,0,25){
occ[0][c] = inf;
occ[1][c] = 0;
}
rep(i,1,m){
chkmin(occ[0][_t[i] - 'a'],i);
chkmax(occ[1][_t[i] - 'a'],i);
}
rep(c,0,25){
if(occ[0][c] > occ[1][c]) continue;
delta[occ[0][c]] += 1 << c;
delta[occ[1][c] + 1] -= 1 << c;
}
rep(i,1,m) delta[i] += delta[i - 1];
for(int l = 1,r;l <= m;l = r + 1){
r = l;
while(r < m && delta[r] == delta[r + 1]) r++;
_bas[++sz] = delta[l];
if(occ[0][_t[l] - 'a'] == l) _occ[sz] = _t[l];
rep(i,l,r) s[sz][++_len[sz]] = _t[i];
}
/* rep(i,1,sz){
printf("seg %d bas=%d occ=%d\n",i,_bas[i],_occ[i]);
rep(j,1,_len[i]) printf("%c",s[i][j]);
printf("\n");
}*/
rep(i,1,n) scanf("%d",&w[i]);
rep(p,1,sz){
k = 0;
rep(i,1,n){
nxt[i] = 0;
if((_bas[p] >> (_s[i] - 'a')) & 1){
nxt[i] = ++k;
idx[k] = i;
t[k] = _s[i];
}
}
nxt[n + 1] = n + 1;
per(i,n,1) if(!nxt[i]) nxt[i] = nxt[i + 1];
slv(p);
}
ll answer = linf;
memset(dp,0x3f,sizeof(dp));
dp[0][0] = 0;
rep(i,1,n){
rep(p,0,sz){
if(((_bas[p] >> (_s[i] - 'a')) & 1) == 0) chkmin(dp[p][i],dp[p][i - 1]);
if(!p || cst[p][i] == linf) continue;
chkmin(dp[p][ch[p][i]],dp[p - 1][i - 1] + cst[p][i]);
}
chkmin(answer,dp[sz][i]);
}
rep(i,1,n) if(occ[0][_s[i] - 'a'] == inf) answer += w[i];
if(answer < linf) printf("%lld\n",answer);
else printf("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: 4ms
memory: 112864kb
input:
ababccb abc 7 2 2 4 3 2 1
output:
7
result:
ok single line: '7'
Test #2:
score: 0
Accepted
time: 8ms
memory: 112648kb
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: 23ms
memory: 119452kb
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: 52ms
memory: 139528kb
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: 198ms
memory: 234172kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
You better start from scratch man...
result:
ok single line: 'You better start from scratch man...'
Test #6:
score: 0
Accepted
time: 28ms
memory: 119256kb
input:
bbaaaabbbbbabaababbaaabbbabaaaababaababaabababbbbabbbbababaabaaabbabaaaabbbabbaababababbabbbabbaababaaaaaabbabbbababbaabbbabbbabbbabaababaaaaaabaaababbbbbbaabaabaaaaaaabbbaaabaabbbababbbbbabbababaababaabbababbaababbbbbbbbbbbaabbbbbabaaabaabaaabaaaaabaaaabbbbbbbaaaabaabbbababbaaaabbabababbbabbbbabbab...
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 88ms
memory: 172668kb
input:
hdhlkjabgckjkagfgkigfebfjmdabahajicgkfmblafmfgkiimkjlciiaegbkbkicgklhbhfmclghkleghmckbjliiicmmecldieghfdeghgechcjahdfebkhdigbkklcclieccijaemchbmfcggcjmgbdjhcbacleajjjledkfdjebgdmgahkjigjjighlbedbellabffeeckfbghcblmmgjijdehmcameeledejfijfmfcfkjdjklfldhmkabblcbgebhibkmihelehjccgggjhhbjehfidfmmjdgmmjbf...
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 187ms
memory: 239652kb
input:
soibsuydrizsuvymezuyrewmgwpnzxgyggpzjkdzooisgzbkfqjzkfcklluotqpwganvksoqtzixkfkrtqobdnregwgkxjwzsruvhztscxjyqlhfytomzhxiglxemdhkjnskrsqngojffogrkbygmdgzfwrlhwhhngqpjpepqgynsdybhpuaqhgjroijqofiwnxgxdmhofwsjnmwitruiesefzmabcfsyzrrruidewjowfkwwwqhztsmmtdnejlqhkmbpmknlxijnmzbtqviburbqwufipqsrqplcelovsxz...
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 3ms
memory: 110968kb
input:
aaaaaaaaaa a 670064684 12247274 885150692 755303894 373857482 772871474 451986656 733926307 275101324 732261937
output:
4777621032
result:
ok single line: '4777621032'
Test #10:
score: 0
Accepted
time: 3ms
memory: 110288kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa 807194254 763061330 636628022 447638039 310117480 873320507 134259988 666480259 747042520 231541618 643931761 30317274 158530414 253502390 229547045 438239031 709645547 367432988 755781758 67144518 360508870 862615691 635226301 863755466 104979114 4...
output:
5115514604
result:
ok single line: '5115514604'
Test #11:
score: 0
Accepted
time: 4ms
memory: 109804kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaa 768295104 305748099 281563038 518303412 678146171 512832379 509999474 360793781 979858190 884904151 886121576 776530718 147119220 985829130 553994391 500082956 167860347 562080893 520228135 790526162 270707017 179265550 913606870 245853815 83...
output:
21140461276
result:
ok single line: '21140461276'
Test #12:
score: 0
Accepted
time: 12ms
memory: 110360kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 684483834 637018127 270602950 736485564 883414052 758886073 266638494 906099301 851227039 479339928 603217972 474167559 537788182 324629484 719852776 8079...
output:
27302362948
result:
ok single line: '27302362948'
Test #13:
score: 0
Accepted
time: 3ms
memory: 110696kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
131859070652
result:
ok single line: '131859070652'
Test #14:
score: 0
Accepted
time: 8ms
memory: 109844kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
781196173176
result:
ok single line: '781196173176'
Test #15:
score: 0
Accepted
time: 8ms
memory: 107016kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
4343956108320
result:
ok single line: '4343956108320'
Test #16:
score: 0
Accepted
time: 12ms
memory: 111204kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
18494567762260
result:
ok single line: '18494567762260'
Test #17:
score: 0
Accepted
time: 20ms
memory: 111868kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
32209183658799
result:
ok single line: '32209183658799'
Test #18:
score: 0
Accepted
time: 12ms
memory: 110444kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
54681136007004
result:
ok single line: '54681136007004'
Test #19:
score: 0
Accepted
time: 12ms
memory: 115676kb
input:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
29370598770431
result:
ok single line: '29370598770431'
Test #20:
score: 0
Accepted
time: 10ms
memory: 110448kb
input:
aaaabababb bb 476848657 19478030 860633182 479517749 926931997 990353030 811177212 276072809 44418816 639422667
output:
3786744940
result:
ok single line: '3786744940'
Test #21:
score: 0
Accepted
time: 8ms
memory: 113952kb
input:
baabbbaabbbbbbaaabbabababbbabb aabbbbbbbbbbbb 596942736 513321407 582182914 466363879 661702687 696876564 738552457 374802663 475543850 315580035 306727219 980454952 485808481 677883937 518967937 895712736 991586358 554417767 795851770 921017576 109301858 423859119 202619045 804565823 583428190 4070...
output:
9486081373
result:
ok single line: '9486081373'
Test #22:
score: -100
Wrong Answer
time: 3ms
memory: 112068kb
input:
bbaaaaababbaabbbabaaaaaaaaaaaaaaabaabaabbabbbbaaaa bba 517088091 307183015 994179974 164146474 156595248 11692792 656694126 683962150 307132163 246359231 966105863 281059597 304728259 612665622 916423647 405320553 230841790 746930714 950416681 343242506 418374186 670629995 146835514 191417218 469803...
output:
21936514047
result:
wrong answer 1st lines differ - expected: '21735754192', found: '21936514047'