QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#530734#6539. Treasure BoxyqrWA 1ms9892kbC++202.4kb2024-08-24 17:04:282024-08-24 17:04:28

Judging History

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

  • [2024-08-24 17:04:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9892kb
  • [2024-08-24 17:04:28]
  • 提交

answer

#include<stdio.h>
#include<ctype.h>
#include<memory.h>
#include<set>
namespace IO {
	constexpr int bufsize = 230005;
	char buf[bufsize], *f1, *f2;
	char gtchar() {return f1 == f2 && (f2 = buf + fread(f1 = buf, 1, bufsize, stdin)) == buf? EOF: *f1++;}
	template<typename t> void read(t &ret)
	{
		int f = ret = 0;
		char ch = gtchar();
		while(!isdigit(ch)) f = ch == '-', ch = gtchar();
		while(isdigit(ch)) ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = gtchar();
		if(f) ret = -ret;
	}
	template<typename t, typename ...T> void read(t &a, T &...b) {read(a), read(b...);}
}using IO::read, IO::gtchar;
typedef long long ll;
constexpr int maxn = 1000005;
int n, val[maxn];
ll C, f[maxn], g[maxn];
char s[maxn];
ll min(ll a, ll b) {return a > b? b: a;}
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int T;
	read(T);
	while(T--)
	{
		read(n, C);
		for(int i = 0; i <= n + 1; i++) f[i] = g[i] = 0x3f3f3f3f3f3f3f3f;
		char ch = gtchar();
		while(!isalpha(ch)) ch = gtchar();
		for(int i = 1; i <= n; i++) s[i] = ch, ch = gtchar();
		int cnt = 0;
		for(int i = 1, j = n; i < j; i++, j--) if(s[i] != s[j]) ++cnt;
		if(!cnt)
		{
			for(int i = 1; i <= n; i++) printf("0 ");
			return puts(""), 0;
		}
		int mid = n / 2, cc = 0;
		ll sum = 0;
		std::set<int> pos;
		for(int i = 1; i <= n; i++)
		{
			read(val[i]);
			if(s[i] != s[n - i + 1])
			{
				if(i <= mid) sum += val[i], ++cc, pos.insert(i);
				else if(val[i] < val[n - i + 1]) sum += val[i] - val[n - i + 1], pos.erase(n - i + 1), pos.insert(i);
			}
			if(cc == cnt) f[i] = sum + (i - *pos.begin()) * C;
		}
		pos.clear();
		sum = cc = 0;
		for(int i = n; i; i--)
		{
			if(s[i] != s[n - i + 1])
			{
				if(i > mid) sum += val[i], ++cc, pos.insert(i);
				else if(val[i] < val[n - i + 1]) sum += val[i] - val[n - i + 1], pos.erase(n - i + 1), pos.insert(i);
			}
			if(cc == cnt) g[i] = sum + (*pos.rbegin() - i) * C;
		}
		for(int i = 1; i <= n; i++) f[i] = min(f[i], f[i - 1] + C);
		for(int i = n; i; i--) g[i] = min(g[i], g[i + 1] + C);
		ll mn = 0x3f3f3f3f3f3f3f3f;
		for(int i = 1; i <= n; i++) f[i] = min(f[i], mn + i * C), mn = min(mn, g[i] - i * C);
		mn = 0x3f3f3f3f3f3f3f3f;
		for(int i = n; i; i--) g[i] = min(g[i], mn - i * C), mn = min(mn, f[i] + i * C);
		for(int i = 1; i <= n; i++) printf("%lld ", min(f[i], g[i]));
		puts("");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9892kb

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: 0ms
memory: 9884kb

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: 1ms
memory: 8168kb

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 30 
21 17 13 9 13 13 9 13 17 21 
27 23 22 18 22 19 15 19 23 27 
0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 10th numbers differ - expected: '22', found: '30'