为什么RE了?
查看原帖
为什么RE了?
733553
huangluyi2008楼主2023/7/9 14:02
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, a[40005], b[40005], c[40005], A[40005], B[40005], cnt[5];
string ans[1000005];
int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		c[i] = a[i];
		A[a[i]] = 1;
	}
	for (int i = 1, j = n; i <= j; ++i, --j) {
		swap (a[i], a[j]);
	}
	cnt[1] = n;
	sort(c + 1, c + 1 + n);
	for (int i = n; i >= 1; --i) {
		if (A[c[i]]) {
			while (A[c[i]]) {
//				if (cnt[1] > 4e4 || cnt[1] < 0 || cnt[2] > 4e4 || cnt[2] < 0) exit(0);
				if (a[cnt[1]] == c[i]) {
					ans[++cnt[3]] = "A C";
					A[c[i]] = 0;
					cnt[1]--;
					break;
				}
				ans[++cnt[3]] = "A B";
				A[a[cnt[1]]] = 0;
				B[a[cnt[1]]] = 1;
				b[++cnt[2]] = a[cnt[1]--];
			}
		}
		else {
			while (B[c[i]]) {
//				if (cnt[1] > 4e4 || cnt[1] < 0 || cnt[2] > 4e4 || cnt[2] < 0) exit(0);
				if (b[cnt[2]] == c[i]) {
					ans[++cnt[3]] = "B C";
					B[c[i]] = 0;
					cnt[2]--;
					break;
				}
				ans[++cnt[3]] = "B A";
				B[b[cnt[2]]] = 0;
				A[b[cnt[2]]] = 1;
				a[++cnt[1]] = b[cnt[2]--];
			}
		}
		
	}
	cout << cnt[3] << '\n';
	for (int i = 1; i <= cnt[3]; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}
2023/7/9 14:02
加载中...