这是什么原因导致的RE?
Runtime Error.
Received signal 6: Aborted / IOT trap.
代码
#include<bits/stdc++.h>
using namespace std;
string ans[4000000];
stack<int> A,B,C;
long long n,Cnt;
long long a[40005],b[40005];
bool find(stack<int> stk,int x){
while(!stk.empty()){
if(stk.top()==x)
return true;
stk.pop();
}
return false;
}
int main(){
ios::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
}
sort(b+1,b+n+1,greater<int>());
for(int i=n;i>=1;i--)
A.push(a[i]);
for(int i=1;i<=n;i++){
if(find(A,b[i])){
while(A.top()!=b[i]){
ans[++Cnt]="A B";
B.push(A.top());
A.pop();
}
ans[++Cnt]="A C";
A.pop();
}else{
while(B.top()!=b[i]){
ans[++Cnt]="B A";
A.push(B.top());
B.pop();
}
ans[++Cnt]="B C";
B.pop();
}
}
cout<<Cnt<<endl;
for(int i=1;i<=Cnt;i++)
cout<<ans[i]<<endl;
return 0;
}