#include <bits/stdc++.h>
#include "swaps.h"
int n ;
vector<int>solve()
{
vector< vector<int> >v ;
for(int i = 1 ; i <= n ; ++i)
v.push_back({i}) ;
while(v.size() > 1)
{
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)
{
for(auto &a : state)
{
if(a[2] < v[a[0]].size() && a[3] < v[a[1]].size())
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())
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())
schedule(v[a[1]][a[3]] , v[a[1]][a[3]+1]) ;
}
vector<int>cur = visit() ;
int idx = 0 ;
for(auto &a : state)
{
int idx2 = a[0] / 2 ;
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]++ ;
++idx ;
}
else if(a[2] < v[a[0]].size() && a[3] == v[a[1]].size())
{
if(cur[idx])
v2[idx].push_back(v[a[0]][a[2]]) ;
else
v2[idx].push_back(v[a[0]][a[2]+1]) ;
a[2]++ ;
if(a[2] == (int)(v[a[0]].size()) - 1)
v2[idx].push_back(v[a[0]][a[2]]) , a[2]++ ;
}
else if(a[2] == v[a[0]].size() && a[3] < v[a[1]].size())
{
if(cur[idx])
v2[idx].push_back(v[a[1]][a[3]]) ;
else
v2[idx].push_back(v[a[1]][a[3]+1]) ;
a[3]++ ;
if(a[3] == (int)(v[a[1]].size()) - 1)
v2[idx].push_back(v[a[1]][a[3]]) , a[3]++ ;
}
}
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 ;
answer(solve()) ;
return ;
}
Compilation message
swaps.cpp:6:1: error: 'vector' does not name a type
6 | vector<int>solve()
| ^~~~~~
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:85:15: error: too few arguments to function 'void solve(int, int)'
85 | answer(solve()) ;
| ^
swaps.cpp:82:6: note: declared here
82 | void solve(int N, int V)
| ^~~~~