Submission #820132

#TimeUsernameProblemLanguageResultExecution timeMemory
820132MohamedAhmed04The Collection Game (BOI21_swaps)C++14
5 / 100
3053 ms352 KiB
#include <bits/stdc++.h> #include "swaps.h" using namespace std ; const int MAX = 510 ; int n , q ; mt19937 rng(6000) ; int mark[MAX] ; int cntq = 0 ; vector<int>solve() { vector< vector<int> >v ; for(int i = 1 ; i <= n ; ++i) v.push_back({i}) ; while(v.size() > 1) { memset(mark , 0 , sizeof(mark)) ; //shuffle(v.begin() , v.end() , rng) ; vector< vector<int> >v2 ; int sz = v.size() ; vector< array<int , 4> >state ; for(int i = 0 ; i < sz-1 ; i += 2) { state.push_back({i , i+1 , 0 , 0}) ; v2.push_back({}) ; } if((sz & 1)) v2.push_back(v[sz-1]) ; bool ok = false ; while(!ok) { int cnt = 0 ; bool bayez = false ; for(auto &a : state) { bool flag = false ; if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size()) { cnt++ , schedule(v[a[0]][a[2]] , v[a[0]][a[2]+1]) ; flag = true ; } if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size()) { cnt++ , schedule(v[a[1]][a[3]] , v[a[1]][a[3]+1]) ; flag = true ; } if(flag) continue ; if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size()) cnt++ , schedule(v[a[0]][a[2]] , v[a[1]][a[3]]) ; else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size()) cnt++ , schedule(v[a[0]][a[2]] , v[a[0]][a[2]+1]) ; else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size()) { cnt++ , schedule(v[a[1]][a[3]] , v[a[1]][a[3]+1]) ; } } vector<int>cur ; if(cnt) { cntq++ ; if(cntq > q) while(1) ; cur = visit() ; } int idx = 0 ; for(auto &a : state) { bool flag = false ; int idx2 = a[0] / 2 ; if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size()) { flag = true ; if(!cur[idx]) swap(v[a[0]][a[2]] , v[a[0]][a[2]+1]) ; ++idx ; } if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size()) { if(!cur[idx]) swap(v[a[1]][a[3]] , v[a[1]][a[3]+1]) ; ++idx ; flag = true ; } mark[a[0]] = mark[a[1]] = 0 ; if(flag) continue ; if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size()) { if(cur[idx]) v2[idx2].push_back(v[a[0]][a[2]]) , a[2]++ ; else v2[idx2].push_back(v[a[1]][a[3]]) , a[3]++ ; if(a[2] == v[a[0]].size() && a[3] == (int)(v[a[1]].size()) - 1) v2[idx2].push_back(v[a[1]][a[3]]) , a[3]++ ; else if(a[3] == v[a[1]].size() && a[2] == (int)(v[a[0]].size()) - 1) v2[idx2].push_back(v[a[0]][a[2]]) , a[2]++ ; mark[a[0]] = mark[a[1]] = 1 ; ++idx ; } else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size()) { if(!cur[idx]) swap(v[a[0]][a[2]] , v[a[0]][a[2]+1]) ; v2[idx2].push_back(v[a[0]][a[2]]) ; a[2]++ ; if(a[2] == (int)(v[a[0]].size()) - 1) v2[idx2].push_back(v[a[0]][a[2]]) , a[2]++ ; ++idx ; } else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size()) { if(!cur[idx]) swap(v[a[1]][a[3]] , v[a[1]][a[3]+1]) ; v2[idx2].push_back(v[a[1]][a[3]]) ; a[3]++ ; if(a[3] == (int)(v[a[1]].size()) - 1) v2[idx2].push_back(v[a[1]][a[3]]) , a[3]++ ; ++idx ; } } ok = true ; for(auto &a : state) ok &= (a[2] == v[a[0]].size() && a[3] == v[a[1]].size()) ; } v = v2 ; } return v[0] ; } void solve(int N, int V) { n = N , q = V ; answer(solve()) ; return ; }

Compilation message (stderr)

swaps.cpp: In function 'std::vector<int> solve()':
swaps.cpp:43:31: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:43:56: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:48:31: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size())
swaps.cpp:48:56: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size())
swaps.cpp:55:13: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:55:38: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:57:18: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size())
swaps.cpp:57:43: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size())
swaps.cpp:59:18: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:59:44: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:77:31: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:77:56: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     if(mark[a[0]] && a[2] + 1 < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:84:31: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size())
swaps.cpp:84:56: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     if(mark[a[1]] && a[3] + 1 < v[a[1]].size() && a[2] < v[a[0]].size())
swaps.cpp:94:13: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:94:38: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:100:14: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |      if(a[2] == v[a[0]].size() && a[3] == (int)(v[a[1]].size()) - 1)
swaps.cpp:102:19: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |      else if(a[3] == v[a[1]].size() && a[2] == (int)(v[a[0]].size()) - 1)
swaps.cpp:107:18: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size())
swaps.cpp:107:43: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size())
swaps.cpp:117:18: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:117:44: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size())
swaps.cpp:130:17: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     ok &= (a[2] == v[a[0]].size() && a[3] == v[a[1]].size()) ;
swaps.cpp:130:43: warning: comparison of integer expressions of different signedness: 'std::array<int, 4>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     ok &= (a[2] == v[a[0]].size() && a[3] == v[a[1]].size()) ;
swaps.cpp:39:9: warning: unused variable 'bayez' [-Wunused-variable]
   39 |    bool bayez = false ;
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...