Submission #496165

# Submission time Handle Problem Language Result Execution time Memory
496165 2021-12-20T20:52:38 Z asandikci Slagalica (COCI19_slagalica2) C++17
10 / 70
66 ms 7740 KB
#include"iostream"
#include"vector"
// #include"queue"
// #include"deque"
#include"set"
// #include"map"
#include"algorithm"
// #include"iomanip"
// #include"cstring"
// #include"cmath"
// #include"bitset"
#define int long long
using namespace std;  

const int INF=1e9;
const int maxn=1e5;
int sbmp=0,ebmp=0;
set<int> st[7];

bool check(int a,int b,int c,int d){
  if(a<0 || b<0 || c<0 || d<0){return 0;}
  if(a==0 && b==0 && c==0 && d==0){return 1;}
  // cout << a << " " << b << " " << c <<" " << d << "\n"; 
  if(sbmp==1 && ebmp==0){
    // cout << "asd?";
    if(a==d){
      if(a==0 && b!=0){
        return 0;
      }
      else{
        return 1;
      }
    }
    return 0;
  }
  if(sbmp==0 && ebmp==1){
    if(a==d){
      if(a==0 && c!=0){
        return 0;
      }
      else{
        return 1;
      }
    }
    return 0;
  }
  if(sbmp==1 && ebmp==1){
    if(a==d-1){
      return 1;
    }
    return 0;
  }
  if(sbmp==0 && ebmp==0){
    // cout << a << " " << b << " " << c <<" " << d << "\n"; 
    if(d==a-1){
      return 1;
    }
    return 0;
  }
  cout << "wha?";
  return 0;
}



void solve(){
  int n,a,b;
  cin >> n;

  pair<int,int> start,end;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    if(a<=4)
    st[a].insert(b);
    else if(a<=6)
    start={a,b};
    else if(a<=8)
    end={a,b};
  }
  // for(int i=0;i<5;i++){
  //   cout << st[i].size() << "\n";
  // }
  
  if(start.first==5){
    sbmp=1;
  }
  if(end.first==7){
    ebmp=1;
  }
  vector<int> ans;
  for(int i=1;i<n-1;i++){
    int mini=1e9;
    int mininum=0;
    sbmp=1;
    if(check(st[1].size()-1,st[2].size(),st[3].size(),st[4].size())){
      mini = min(mini,*(st[1].begin()));
      mininum=1;
    }
    sbmp=0;
    if(check(st[1].size(),st[2].size()-1,st[3].size(),st[4].size())){
      mini = min(mini,*(st[2].begin()));
      mininum=2;
    }
    sbmp=1;
    if(check(st[1].size(),st[2].size(),st[3].size()-1,st[4].size())){
      mini = min(mini,*(st[3].begin()));
      mininum=3;
    }
    sbmp=0;
    if(check(st[1].size(),st[2].size(),st[3].size(),st[4].size()-1)){
      mini = min(mini,*(st[4].begin()));
      mininum=4;
    }
    ans.push_back(mini);
    if(mini==1e9){cout << "-1";return;}
    if(mininum==1 || mininum==3){sbmp=1;}
    if(mininum==2 || mininum==4){sbmp=0;}
    st[mininum].erase(*(st[mininum].begin()));
    // cout << "\n";
  }
  cout << start.second << " ";
  for(auto it : ans){
    cout << it << " ";
  }
  cout << end.second << " ";
  // for(int i=0;i<5;i++){
  //   cout << st[i].size() << "\n";
  // }




}

signed main(){
  ios::sync_with_stdio(false); cin.tie(0);
  // freopen("","r",stdin);freopen("","w",stdout);
  int t=1;
  // cin >> t;
  for(int i=1;i<=t;i++){
    // cout << "Case " << i << ":\n";
    solve();
    // cout <<"\n\n";
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 316 KB Output is correct
2 Incorrect 1 ms 312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6988 KB Output is correct
2 Incorrect 62 ms 7664 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6720 KB Output is correct
2 Incorrect 47 ms 7024 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 6116 KB Output is correct
2 Correct 48 ms 7148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 6916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 6980 KB Output is correct
2 Correct 39 ms 5688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 6836 KB Output is correct
2 Incorrect 50 ms 7332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 5304 KB Output is correct
2 Incorrect 51 ms 6736 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 7740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 6528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 7728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 6468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 6568 KB Output isn't correct
2 Halted 0 ms 0 KB -