QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398441 | #6539. Treasure Box | eggegg185 | WA | 10ms | 12056kb | C++14 | 1.6kb | 2024-04-25 12:30:17 | 2024-04-25 12:30:22 |
Judging History
answer
#include <iostream>
using namespace std;
#define int long long
const int maxn = 1e6+10;
int n,C,a[maxn],app[maxn],tot = 0,rr[maxn],ll[maxn]; char s[maxn];
void solve(int ans[]) {
int ss = 0,tt = 0; tot = 0;
for(int i = 1; i <= n+1-i; i++) {
if(s[i] != s[n+1-i]) ss = (!ss)?i:ss,tt = i;
}
for(int i = 1; i <= n; i++) if(s[i] != s[n+1-i]) app[++tot] = i;
if(!ss) {for(int i = 1; i <= n; i++) ans[i] = 0; return ;}
int cum = 0;
for(int i = ss; i <= tt; i++) if(s[i] != s[n+1-i]) cum += a[i];
ans[ss] = cum + C*(tt-ss); //printf("%lld\n",ans[ss]);
for(int i = (tot>>1)+1; i <= tot; i++) {
int x = app[i];
if(s[x] != s[n+1-x]) cum += min(a[x],a[n+1-x])-a[n+1-x];
ans[ss] = min(ans[ss],cum+C*(x-ss));
//printf("%lld %lld\n",cum,x);
} //printf("%lld\n",ans[ss]);
for(int i = ss-1; i >= 1; i--) ans[i] = ans[i+1]+C;
for(int i = ss+1; i <= app[(tot>>1)+1]; i++) {
if(s[i-1] != s[n+2-i]) cum += a[n+2-i]-min(a[i-1],a[n+2-i]);
ans[i] = cum+C*(app[tot]-i);
}
//for(int i = 1; i <= n; i++) printf("%lld ",ans[i]); putchar('\n');
for(int i = 2; i <= n; i++) {
if(ans[i]) ans[i] = min(ans[i-1]+C,ans[i]);
else ans[i] = ans[i-1]+C;
}
//for(int i = 1; i <= n; i++) printf("%lld ",ans[i]); putchar('\n');
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
int T; cin >> T;
while(T--) {
tot = 0;
cin >> n >> C >> (s+1); for(int i = 1; i <= n; i++) cin >> a[i];
solve(rr); tot = 0;
for(int i = 1; i <= n; i++) if(i<n+1-i) swap(a[i],a[n+1-i]); solve(ll);
for(int i = 1; i <= n; i++) printf("%lld ",min(rr[i],ll[n+1-i]));
putchar('\n');
//for(int i = 1; i <= n; i++) app[i] = 0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12056kb
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: 12052kb
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: -100
Wrong Answer
time: 10ms
memory: 9932kb
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 21 17 13 18 22 19 15 13 15 19 0 0 0 0 0 0 0 0 0 0 11 7 3 7 11 15 12 8 12 16 11 7 3 7 11 11 7 8 12 16 11 7 3 7 30 34 7 8 12 16 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 8 4 8 6 10 14 10 6 2 6 8 4 8 6 19 19 ...
result:
wrong answer 21st numbers differ - expected: '22', found: '21'