This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define NDEBUG
#ifdef NDEBUG
#define dbg(TXTMSG) if constexpr (false) cerr << "lol"
#define dbgv(VARN) ((void)0)
#define dbgfor(COND) if constexpr (false) for (COND)
#else
#define _GLIBCXX_DEBUG 1
#define _GLIBCXX_DEBUG_PEDANTIC 1
#pragma GCC optimize("trapv")
#define dbg(TXTMSG) cerr << "\n" << TXTMSG
#define dbgv(VARN) cerr << "\n" << #VARN << " = "<< VARN << ", line: " << __LINE__ << "\n"
#define dbgfor(COND) for (COND)
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = int;
using pll = pair<ll,ll>;
#define e0 first
#define e1 second
//constexpr ll INFTY = 2e18;
ll N;
ll find_remove(ll to_rem, deque<ll>& find_in, deque<ll>& temp)
{
swap(find_in,temp);
find_in.resize(temp.size()-1);
ll i;
for (i = 0; temp[i]!=to_rem; ++i)
{
find_in[i] = temp[i];
}
for (ll j = i; j < ll(find_in.size()); ++j)
{
find_in[j] = temp[j+1];
}
return i;
}
int main()
{
cin >> N;
vector<ll> P(N);
for (ll i = 0; i < N; ++i)
{
cin >> P[i];
}
if (N==1) {
cout << "0";
return 0;
}
vector<pair<ll,char>> outp;
deque<ll> remain(P.cbegin(),P.cend());
deque<ll> temp;
ll curr=1;
while (remain.size()>2)
{
ll i = find_remove(curr, remain, temp);
outp.push_back({-i,'a'});
for (; i > 1; i-=2)
{
outp.push_back({2,'a'});
outp.push_back({1,'b'});
}
if (i==1)
{
outp.push_back({1,'a'});
outp.push_back({2,'b'});
swap(remain[0],remain[1]);
i--;
}
assert(i==0);
outp.push_back({-1,'a'});
curr++;
}
if (remain[0]==N-1)
{
outp.push_back({-2,'a'});
}
else
{
assert(remain[0]==N);
dbgv("g");
if (N%2==1)
{
cout << "NIE DA SIE";
return 0;
}
for (ll i = 0; i < (N/2)-1; ++i)
{
outp.push_back({2,'a'});
outp.push_back({1,'b'});
}
outp.push_back({-1,'a'});
}
for (ll fff=0;fff<2;fff++)
{
vector<pair<ll,char>> newoutp;
pair<ll,char> currcmd={0,'z'};
for (pair<ll,char> cmd : outp)
{
dbgv(cmd.e0 << cmd.e1);
if (cmd.e1==currcmd.e1) currcmd.e0+=cmd.e0;
else
{
if (currcmd.e0!=0){
newoutp.push_back({currcmd.e0, currcmd.e1});
}
currcmd=cmd;
}
if (currcmd.e1=='a') {
currcmd.e0+=2*N;
currcmd.e0%=N;
}
else
{
currcmd.e0+=6;
currcmd.e0%=3;
}
}
if (currcmd.e0!=0){
newoutp.push_back({currcmd.e0, currcmd.e1});
}
swap(outp,newoutp);
}
stringstream stroutp;
ll osize = 0;
{
pair<ll,char> currcmd={0,'z'};
for (pair<ll,char> cmd : outp)
{
dbgv(cmd.e0 << cmd.e1);
if (cmd.e1==currcmd.e1) currcmd.e0+=cmd.e0;
else
{
if (currcmd.e0!=0){
osize+=1;
stroutp << currcmd.e0 << currcmd.e1 << " ";
}
currcmd=cmd;
}
if (currcmd.e1=='a') {
currcmd.e0+=2*N;
currcmd.e0%=N;
}
else
{
currcmd.e0+=6;
currcmd.e0%=3;
}
}
if (currcmd.e0!=0){
osize+=1;
stroutp << currcmd.e0 << currcmd.e1 << " ";
}
}
cout << osize << "\n";
cout << stroutp.str();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |