QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#314944 | #7857. (-1,1)-Sumplete | one_god_and_two_dogs# | RE | 0ms | 0kb | C++17 | 1.0kb | 2024-01-26 15:18:21 | 2024-01-26 15:18:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll=long long ;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin>>n;
vector<int>stk;
vector<int>ind(n);
vector<vector<int>>G(n);
vector<pair<int,int>>ans;
for(int i=0;i<n;++i){
int x;
cin>>x;
--x;
while(!stk.empty()&&stk.back()<x)
stk.pop_back();
if(!stk.empty()){
ans.emplace_back(stk.back(),x);
G[stk.back()].emplace_back(x);
++ind[x];
}
stk.emplace_back(x);
}
stk.clear();
for(int i=0;i<n;++i){
int x;
cin>>x;
--x;
while(!stk.empty()&&stk.back()>x)
stk.pop_back();
if(!stk.empty()){
ans.emplace_back(stk.back(),x);
G[stk.back()].emplace_back(x);
++ind[x];
}
stk.emplace_back(x);
}
queue<int>que;
for(int i=0;i<n;++i)if(!ind[i])que.push(i);
while(!que.empty()){
int x=que.front();
que.pop();
for(auto y:G[x])
if(--ind[y]==0)que.push(y);
}
for(int i=0;i<n;++i){
if(ind[i]){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
for(auto [x,y]:ans){
cout<<x+1<<" "<<y+1<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 +-+ -++ +-+ 1 1 1 1 -1 3