WA70求调
  • 板块P9518 queue
  • 楼主Expert_Dream
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/8/13 08:52
  • 上次更新2023/11/3 04:09:58
查看原帖
WA70求调
768530
Expert_Dream楼主2023/8/13 08:52
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5 + 5;
string que[N];
map<string,int> mp;
map<string,int> pl;
int len=0;
queue<string> q;
int head,till;
//int vis[N];
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
//	freopen("xx.out","w",stdout);
	while(n--){
		string sj;
		cin >> sj;
		string x;
		
		if(sj == "start"){//新游戏
//			cout<<"**"<<len;
			if(!len){
				cout << "Error\n";
			}else{
//				if(q.empty()){
//					cout<<"Error\n";
//				}
				
				while(!q.empty()){
					que[++till] = q.front();
					pl[q.front()] = 0 ;
					mp[q.front()] = till;
					len++;
					q.pop();
				}
				int res=0;
				int l2=len;
				for(int i = head;i <= till && res < min(l2,2);i++){
					if(que[i].size() &&!( que[i] == " ")){
						q.push(que[i]);
						cout<<que[i]<<" ";
						pl[que[i]] = 1;
						head = i + 1;
						len--;
						res++;
					}
				}
				cout<<"\n";
				
			}
		}else if(sj=="arrive"){
			cin >> x;
			if(mp[x]||pl[x]){
				cout<<"Error\n";
			}else{
				cout<<"OK\n";
				que[++till] = x;
				len++;
				mp[x] = till;
			}
		}else{
			cin >> x;
			if(mp.find(x) == mp.end()|| pl[x]){
				cout << "Error\n";
			}else{
				cout<<"OK\n";
				que[mp[x]] = " ";
				len--;
				mp.erase(x);
			}
		}
//		cout<<"-------\n";
	}
	return 0;
}
2023/8/13 08:52
加载中...