QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865425#7030. Ultraman vs. Aodzilla and BodzillacbdsopaAC ✓44ms4480kbC++143.0kb2025-01-21 18:21:392025-01-21 18:21:39

Judging History

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

  • [2025-01-21 18:21:39]
  • 评测
  • 测评结果:AC
  • 用时:44ms
  • 内存:4480kb
  • [2025-01-21 18:21:39]
  • 提交

answer

#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define db double
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define sky fflush(stdout)
#define gc getchar
#define pc putchar
namespace IO{
	template<class T>
	inline void read(T &s){
		s = 0;char ch = gc();bool f = 0;
		while(ch < '0' || '9'<ch) {if(ch == '-') f = 1; ch = gc();}
		while('0'<=ch && ch<='9') {s = s * 10 + (ch ^ 48); ch = gc();}
		if(ch == '.'){
			T p = 0.1;ch = gc();
			while('0' <= ch && ch <= '9') {s = s + p * (ch ^ 48);p /= 10;ch = gc();}
		}
		s = f ? -s : s;
	}
	template<class T,class ...A>
	inline void read(T &s,A &...a){
		read(s); read(a...);
	}
	template<class T>
	inline void write(T x){
		if(x<0) {x = -x; pc('-');}
		static char st[40];
		static int top;
		top = 0;
		do{st[++top] = x - x / 10 * 10 + '0';} while(x /= 10);
		while(top) {pc(st[top--]);}
	}
};
using IO::read;
using IO::write;
const int N = 1e5;
ll pre[N + 3];
int ha, hb, ta, tb;
struct Answer{
	ll atk;
	char ans[N + 3];
}a1, a2;
inline void solve(){
	read(ha, hb, ta, tb);
	// kill A first
	int t1 = std::lower_bound(pre + 1, pre + 1 + N, ha) - pre;
	int t2 = std::lower_bound(pre + 1, pre + 1 + N, ha + hb) - pre;
	a1.atk = 1ll * t1 * ta + 1ll * t2 * tb;
	for(int i = 1; i <= t1; ++i){
		a1.ans[i] = 'A';
	}
	for(int i = t1 + 1; i <= t2; ++i){
		a1.ans[i] = 'B';
	}
	if(pre[t2] - pre[t1] < hb){
		a1.ans[pre[t1] - ha] = 'B';
	}
	// kill B first
	t1 = std::lower_bound(pre + 1, pre + 1 + N, hb) - pre;
	a2.atk = 1ll * t1 * tb + 1ll * t2 * ta;
	for(int i = 1; i <= t1; ++i){
		a2.ans[i] = 'B';
	}
	for(int i = t1 + 1; i <= t2; ++i){
		a2.ans[i] = 'A';
	}
	int pos = std::upper_bound(pre + 1, pre + 1 + N, pre[t1] - hb) - pre - 1;
	if(pre[pos] < ha - (pre[t2] - pre[t1]) ){
		int sum = ha - (pre[t2] - pre[t1]) - pre[pos] + pos;
		for(int i = 1; i <= pos - 1; ++i){
			a2.ans[i] = 'A';
		}
		for(int i = pos + 1; i <= t1; ++i){
			if(sum == i){
				a2.ans[i] = 'A';
				break;
			}
		}
	}else{
		for(int i = 1; i <= pos; ++i){
			a2.ans[i] = 'A';
		}
	}
	if(a1.atk < a2.atk){
		printf("%lld ", a1.atk);
		for(int i = 1; i <= t2; ++i){
			pc(a1.ans[i]);
		}pc('\n');
	}else if(a1.atk > a2.atk){
		printf("%lld ", a2.atk);
		for(int i = 1; i <= t2; ++i){
			pc(a2.ans[i]);
		}pc('\n');
	}else{
		bool flag = 0;
		for(int i = 1; i <= t2; ++i){
			if(a1.ans[i] != a2.ans[i]){
				if(a1.ans[i] < a2.ans[i]){
					printf("%lld ", a1.atk);
					for(int j = 1; j <= t2; ++j){
						pc(a1.ans[j]);
					}pc('\n');
				}else{
					printf("%lld ", a2.atk);
					for(int j = 1; j <= t2; ++j){
						pc(a2.ans[j]);
					}pc('\n');
				}
				flag = 1;
				break;
			}
		}
		if(!flag){
			printf("%lld ", a1.atk);
			for(int i = 1; i <= t2; ++i){
				pc(a1.ans[i]);
			}pc('\n');
		}
	}
}
int main(){
#ifdef LOCAL
	file(a);
#endif
	int T; read(T);
	for(int i = 1; i <= N; ++i){
		pre[i] = pre[i - 1] + i;
	}
	while(T--){
		solve();
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4480kb

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: 44ms
memory: 4480kb

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