QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657983#7030. Ultraman vs. Aodzilla and Bodzillaveg#AC ✓106ms4056kbC++172.0kb2024-10-19 15:55:082024-10-19 15:55:09

Judging History

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

  • [2024-10-19 15:55:09]
  • 评测
  • 测评结果:AC
  • 用时:106ms
  • 内存:4056kb
  • [2024-10-19 15:55:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
long long get(string s, int ha, int hb, int ta, int tb) {
	long long sum = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (ha > 0) sum += ta;
		if (hb > 0) sum += tb;
		if (s[i] == 'A') ha -= i + 1;
		else hb -= i + 1;
	}
	return sum;
}
string f(int ha, int hb, int ta, int tb) {
	string s = "";
	int i;
	long long sum = 0;
	for (i = 1; ; ++i)
		if (ha > i) {
			ha -= i;
			s += 'A';
		} else {
			ha -= i;
			s += 'A';
			break;
		}
	if (ha < 0) {
		s[-ha - 1] = 'B';
		hb += ha;
	}
	if (hb <= 0) return s;
	for (++i; ; ++i)
		if (hb > i) {
			hb -= i;
			s += 'B';
		} else {
			hb -= i;
			s += 'B';
			break;
		}
	if (ha < 0 && hb <= ha) s[-ha - 1] = 'A';
	return s;	
}
string g(int ha, int hb, int ta, int tb) {
	int x = ha, y = hb;
	string s = "";
	int i, final = 0, range = 0;
	long long sum = 0;
	for (i = 1; ; ++i)
		if (hb > i) {
			hb -= i;
			s += 'B';
		} else {
			hb -= i;
			s += 'B';
			break;
		}
	if (hb < 0) {
		hb = -hb;
		for (int j = 1; ; ++j)
			if (hb - j > j) {
				range = j;
				hb -= j;
				ha -= j;
				s[j - 1] = 'A';
				if (ha <= 0) return s;
			} else {
				ha -= hb;
				s[hb - 1] = 'A';
				final = hb;
				break;
			}
	}
	if (ha > 0) {
		for (++i; ; ++i)
			if (ha > i) {
				ha -= i;
				s += 'A';
			} else {
				ha -= i;
				s += 'A';
				break;
			}
	}
	ha = -ha;
	if (final > 0)
		if (final - ha <= range) {
			swap(s[final - 1], s[range]);
		} else {
			swap(s[final - 1], s[final - ha - 1]);
		}
	
	return s;

}
int main() {
	int T;
	cin >> T;
	while (T--) {
		int ha, hb, ta, tb;
		scanf("%d%d%d%d", &ha, &hb, &ta, &tb);
		string x, y;
		x = f(ha, hb, ta, tb);
		y = g(ha, hb, ta, tb);
		long long sx = get(x, ha, hb, ta, tb);
		long long sy = get(y, ha, hb, ta, tb);
		if (sx < sy || sx == sy && x < y) printf("%lld ", sx), cout << x << endl;
		else printf("%lld ", sy), cout << y << endl;
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5 15 5 25
5 15 25 5

output:

155 BBBBBA
105 AAABBB

result:

ok 2 cases

Test #2:

score: 0
Accepted
time: 106ms
memory: 3952kb

input:

100000
1 1 1 1
1 1 1 2
1 1 1 3
1 1 1 4
1 1 1 5
1 1 1 6
1 1 1 7
1 1 1 8
1 1 1 9
1 1 1 10
1 1 2 1
1 1 2 2
1 1 2 3
1 1 2 4
1 1 2 5
1 1 2 6
1 1 2 7
1 1 2 8
1 1 2 9
1 1 2 10
1 1 3 1
1 1 3 2
1 1 3 3
1 1 3 4
1 1 3 5
1 1 3 6
1 1 3 7
1 1 3 8
1 1 3 9
1 1 3 10
1 1 4 1
1 1 4 2
1 1 4 3
1 1 4 4
1 1 4 5
1 1 4 6
1 ...

output:

3 AB
4 BA
5 BA
6 BA
7 BA
8 BA
9 BA
10 BA
11 BA
12 BA
4 AB
6 AB
7 BA
8 BA
9 BA
10 BA
11 BA
12 BA
13 BA
14 BA
5 AB
7 AB
9 AB
10 BA
11 BA
12 BA
13 BA
14 BA
15 BA
16 BA
6 AB
8 AB
10 AB
12 AB
13 BA
14 BA
15 BA
16 BA
17 BA
18 BA
7 AB
9 AB
11 AB
13 AB
15 AB
16 BA
17 BA
18 BA
19 BA
20 BA
8 AB
10 AB
12 AB
14...

result:

ok 100000 cases