Submission #496355

# Submission time Handle Problem Language Result Execution time Memory
496355 2021-12-21T06:17:37 Z asandikci Slagalica (COCI19_slagalica2) C++17
35 / 70
58 ms 7900 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;
  // sbmp ve ebmp ve check fonksiyonunda öncelik karışması var 
  // o anda olduğun yerden itibaren kontrol edeceksin
  
  for(int i=1;i<n-1;i++){
    int mini=1e9;
    int mininum=0;
    if(sbmp==0){
      sbmp=1;
      if(check(st[1].size()-1,st[2].size(),st[3].size(),st[4].size())){
        // cout << ".1";
        mini = min(mini,*(st[1].begin()));
        mininum=1;
      }
      sbmp=0;
    }
    if(sbmp==0){
      sbmp=0;
      if(check(st[1].size(),st[2].size()-1,st[3].size(),st[4].size())){
        // cout << ".2";
        mini = min(mini,*(st[2].begin()));
        mininum=2;
      }
      sbmp=0;
    }
    if(sbmp==1){
      sbmp=1;
      if(check(st[1].size(),st[2].size(),st[3].size()-1,st[4].size())){
        // cout << ".3";
        mini = min(mini,*(st[3].begin()));
        mininum=3;
      }
      sbmp=1;
    }
    if(sbmp==1){
      sbmp=0;
      if(check(st[1].size(),st[2].size(),st[3].size(),st[4].size()-1)){
        // cout << ".4";
        mini = min(mini,*(st[4].begin()));
        mininum=4;
      }
      sbmp=1;
    }
    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 1 ms 204 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6972 KB Output is correct
2 Correct 41 ms 5700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 6760 KB Output is correct
2 Correct 38 ms 5316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 6128 KB Output is correct
2 Correct 52 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 5172 KB Output is correct
2 Correct 46 ms 6592 KB Output is correct
3 Correct 56 ms 7900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 7024 KB Output is correct
2 Correct 53 ms 5604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6844 KB Output is correct
2 Correct 38 ms 5576 KB Output is correct
3 Correct 52 ms 7480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 5320 KB Output is correct
2 Incorrect 48 ms 6724 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 7744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 6468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 7728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 6496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 54 ms 6576 KB Output isn't correct
2 Halted 0 ms 0 KB -