QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210450#6539. Treasure Box275307894aWA 155ms17792kbC++141.6kb2023-10-11 14:42:092023-10-11 14:42:10

Judging History

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

  • [2023-10-11 14:42:10]
  • 评测
  • 测评结果:WA
  • 用时:155ms
  • 内存:17792kb
  • [2023-10-11 14:42:09]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=N*4,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,C,A[N];char s[N];
ll a1[N],a2[N];
void Add(int x,int y,ll w){
	a1[x]=min(a1[x],w);a2[x]=min(a2[x],w);
	a1[y]=min(a1[y],w);a2[y]=min(a2[y],w);
}
void Solve(){
	int i,j;scanf("%d%d",&n,&C);scanf("%s",s+1);
	for(i=1;i<=n;i++) scanf("%d",&A[i]);
	int l=1,r=n;while(l<r&&s[l]==s[r]) l++,r--;
	if(l>=r){for(i=1;i<=n;i++) printf("0 ");printf("\n");return;}
	fill(a1,a1+n+2,INF);fill(a2,a2+n+2,INF);
	int p=n/2;while(s[p]==s[n-p+1]) p--;//cerr<<l<<' '<<r<<'\n';
	ll Sum=0;
	for(i=l;i<=r;i++){
		if(s[i]!=s[n-i+1]) {
			if(i<=n/2) Sum+=A[i];
			else Sum+=min(A[i],A[n-i+1])-A[n-i+1];
		}
		if(i>=p) Add(l,i,Sum+1ll*(i-l)*C);
	}
	p=n-p+1;Sum=0;
	for(i=r;i>=l;i--){
		if(s[i]!=s[n-i+1]) {
			if(i>n/2) Sum+=A[i];
			else Sum+=min(A[i],A[n-i+1])-A[n-i+1];
		}
		if(i<=p) Add(i,r,Sum+1ll*(r-i)*C);
	}
	for(i=1;i<=n;i++) a1[i]=min(a1[i-1]+C,a1[i]);
	for(i=n;i;i--) a2[i]=min(a2[i+1]+C,a2[i]);
	for(i=1;i<=n;i++) printf("%d%c",min(a1[i],a2[i])," \n"[i==n]);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9948kb

input:

2
5 1
ABCDE
7 1 4 5 1
5 1
ABCDA
7 1 4 5 1

output:

6 5 6 6 5
2 1 2 3 4

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 8004kb

input:

1
10 4
AABABBABAB
10 3 4 10 7 1 8 10 7 6

output:

10 14 18 22 26 22 18 14 10 6

result:

ok 10 numbers

Test #3:

score: 0
Accepted
time: 13ms
memory: 8000kb

input:

10000
10 4
ABBBAABABB
6 10 3 9 1 8 5 4 4 10
10 4
BABBAAABAB
3 7 5 9 2 3 9 8 4 1
10 4
ABBBAAABAA
3 2 4 8 2 9 1 9 6 3
10 4
BBAABBAABB
8 8 10 7 1 1 4 9 6 4
10 4
BAABBBBBAB
5 7 3 5 4 2 1 8 2 8
10 4
ABAAAABABA
10 8 2 7 5 3 7 8 10 5
10 4
BBABABAABA
10 6 10 2 2 6 4 4 3 9
10 4
BBBAAAABBB
7 2 2 8 9 10 10 6 7...

output:

17 21 17 21 25 29 26 22 26 22
21 17 13 9 13 13 9 13 17 21
22 18 22 18 22 19 15 19 15 19
0 0 0 0 0 0 0 0 0 0 
11 7 3 7 11 15 12 8 12 16
19 15 11 7 11 11 7 11 15 19
30 34 38 34 30 34 38 42 39 35
0 0 0 0 0 0 0 0 0 0 
11 7 3 7 11 13 9 5 9 13
8 4 8 12 16 14 10 6 2 6
18 14 10 6 10 14 10 14 18 22
27 23 19 ...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 102ms
memory: 9916kb

input:

100000
10 4
BABBBABBAB
8 2 3 10 2 1 10 1 6 4
10 4
BBBAAAABBB
6 4 8 2 6 5 3 7 8 1
10 4
ABAAABAAAB
9 8 8 1 5 4 7 8 2 1
10 4
ABABBBBAAA
8 6 6 3 10 4 5 4 7 3
10 4
AABAABABBA
3 9 9 1 5 6 4 8 2 6
10 4
ABBBAABBBA
7 1 10 2 1 5 1 8 3 7
10 4
BAAABBBAAB
7 10 5 5 1 5 3 5 1 7
10 4
BABAAAAAAB
10 8 7 6 7 10 10 4 8...

output:

18 14 10 6 2 1 5 9 13 17
0 0 0 0 0 0 0 0 0 0 
38 39 35 31 27 23 27 31 27 23
10 6 10 14 18 19 15 11 7 11
30 26 30 27 23 20 24 24 20 24
0 0 0 0 0 0 0 0 0 0 
17 13 9 5 9 7 3 7 11 15
15 11 7 11 15 12 8 4 8 12
4 8 12 16 20 17 13 9 5 1
15 11 7 11 15 11 7 3 7 11
31 27 31 31 27 24 28 28 24 28
17 21 21 17 21...

result:

ok 1000000 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 7912kb

input:

1
1000 4
BABABABBBBABAAAAAABAABBBBBBBBABBBAAAAAABBBBAAABBABABBBBABBBBBBABABBBBAABAAABBBBBBAABABBBAAABABAAAABBBBAAABAABBBABBBAAABBABABABBABAAABAAABBABABABBABAABAABAAABBBBAAABBABBBBABAAABBABBBAAABBABBAABABBABAAAAAABBABAAAABBBBBAABAABBABABAABBAAABBBAAABABAAAABAABBAAABBBAABBABABABBAAAAABBBAAAAAAAABAABBB...

output:

3441 3437 3441 3445 3449 3453 3457 3461 3465 3469 3473 3477 3481 3485 3489 3493 3497 3501 3505 3509 3513 3517 3521 3525 3529 3533 3537 3541 3545 3549 3553 3557 3561 3565 3569 3573 3577 3581 3585 3589 3593 3597 3601 3605 3609 3613 3617 3621 3625 3629 3633 3637 3641 3645 3649 3653 3657 3661 3665 3669 ...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 94ms
memory: 7904kb

input:

1000
1000 4
ABBABBBABBABBAABBABABAAABABAAABAAABAAABABABABABBBAABABBAABAABBBAABBBABBAABAAABBABAAABAAAABAAAAABBBBABBAAABBBABBABABBBABABBABAAABBBBAABBAAABAABBAABBAAAAABAAAABBABBABBAAABBAABBBBABBBAABAAAABAAAAABAAAABABABBBAABBBABAAABBBAAABAAAAABBABAABBABBBAABAABBBBBBAABABBBAAAABBABBAAABBBABBBBABAABAAAABA...

output:

3316 3312 3316 3320 3324 3328 3332 3336 3340 3344 3348 3352 3356 3360 3364 3368 3372 3376 3380 3384 3388 3392 3396 3400 3404 3408 3412 3416 3420 3424 3428 3432 3436 3440 3444 3448 3452 3456 3460 3464 3468 3472 3476 3480 3484 3488 3492 3496 3500 3504 3508 3512 3516 3520 3524 3528 3532 3536 3540 3544 ...

result:

ok 1000000 numbers

Test #7:

score: 0
Accepted
time: 99ms
memory: 7876kb

input:

1000
1000 4
BAABAABAABABABBBABBBAAAABAAAABBAAAABABABAABBBABBBAABBBBABAAABBAABBAAAABAABAAABAAAABAAABBABAAAAABABBBAAABAAAABAABBAAAABBBBAAABBBBBABAABBBBAAAAAABABBBBAABBABBAABABBABAAAAAABAABBABBBAAAAAABAABBABBBBABBBBAAAAAABABBABBABAABABBBBBBABBAABBBAAAAAAAABAAAAAAAAAAABBBBAAABBAABBAAABBBBBABAAAAABBABAAB...

output:

2691 2695 2699 2703 2707 2711 2715 2719 2723 2727 2731 2735 2739 2743 2747 2751 2755 2759 2763 2767 2771 2775 2779 2783 2787 2791 2795 2799 2803 2807 2811 2815 2819 2823 2827 2831 2835 2839 2843 2847 2851 2855 2859 2863 2867 2871 2875 2879 2883 2887 2891 2895 2899 2903 2907 2911 2915 2919 2923 2927 ...

result:

ok 1000000 numbers

Test #8:

score: 0
Accepted
time: 84ms
memory: 15448kb

input:

3
300000 4
BBBBAABABAABBBBBBBBBAAAABAABABBBBABBAABABBBAABABAAABAAABAAAAABAABAAABABBABAABBBBBAABBABAAABAABAABBBAAAAAAABBABABBBABABBBBBBBABBAAAAAABBBABBBBAABAAABBBBABAABAABBAABBAAAABBBABBBAAABAAABAAABABBABBABABBBABBBABABAABBABBBBABAAAABABBAABABAAABABBBBBAABBBABAAAAAAABAAAAAAAABBAAABABBBBBBABAABBBBAABA...

output:

1009294 1009290 1009294 1009298 1009302 1009306 1009310 1009314 1009318 1009322 1009326 1009330 1009334 1009338 1009342 1009346 1009350 1009354 1009358 1009362 1009366 1009370 1009374 1009378 1009382 1009386 1009390 1009394 1009398 1009402 1009406 1009410 1009414 1009418 1009422 1009426 1009430 1009...

result:

ok 900000 numbers

Test #9:

score: 0
Accepted
time: 97ms
memory: 17792kb

input:

3
300000 4
AAAABBBBABAABBBBBABBBABAAABAABBBAAAAABBBAABAABABBABBAAAABBABABBAAABBBBAABBBBBBBBAAABBABBBBBABBABABBBABABBBBBBBABBABBAAABBBBBBBABABABBBABABBAABBBBABABAAAABBABBAAAABBBBAABABABAAAABAAABABBBBAABBBABBBBBBABBBAABBAABBAABBBAABABABBBBABBBAAAABBBAABABBBBABAAAABAAAABABBBAABBABABBBABAABABABBABABAAAA...

output:

640825 640821 640817 640821 640825 640829 640833 640837 640841 640845 640849 640853 640857 640861 640865 640869 640873 640877 640881 640885 640889 640893 640897 640901 640905 640909 640913 640917 640921 640925 640929 640933 640937 640941 640945 640949 640953 640957 640961 640965 640969 640973 640977...

result:

ok 900000 numbers

Test #10:

score: -100
Wrong Answer
time: 155ms
memory: 14576kb

input:

3
300000 123123123
BAAABBAABAAAAAAABBBAAABABBBBBBABBAAABAAAABBBBAAAAAABABBBBBBBAAAAAABABABAABBAAABBABBAAABAAAABBBBAAAAABABBBABAABABAAABABBBAAAABBABABBABABBBBBAAABBAABABABBABBBABBBAAAAABAAABAABBBAAAAAAABBBBBABBBAABABBAABAAAAAAAABAAABAABBAAAAABABABAABBABABBAAABAAAAAABBABBBBABAABABAAAAAAABBABABBAAAAAAA...

output:

-312100093 -188976970 -65853847 57269276 180392399 303515522 426638645 549761768 672884891 796008014 919131137 1042254260 1165377383 1288500506 1411623629 1534746752 1657869875 1780992998 1904116121 2027239244 -2144604929 -2021481806 -1898358683 -1775235560 -1652112437 -1528989314 -1405866191 -12827...

result:

wrong answer 1st numbers differ - expected: '55885802355459', found: '-312100093'