This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=5005;
int n, r, res=INT_MAX, st;
vector<int> p(2*nx), pw(2*nx), npw(2*nx);
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>r;
r=(r%n)+2*n;
for (int i=0; i<2*n; i++) cin>>p[i];
for (int i=0; i<2*n; i+=2)
{
pw[i]=p[0];
for (int j=0; j<i; j++) pw[j]=p[j+1];
for (int j=i+1; j<2*n; j++) pw[j]=p[j];
for (int t=0; t<r; t++)
{
for (int j=2; j<2*n; j+=2)
{
if (pw[j]<pw[j+1]) npw[j-2]=pw[j], npw[j+1]=pw[j+1];
else npw[j-2]=pw[j+1], npw[j+1]=pw[j];
}
if (pw[0]<pw[1]) npw[1]=pw[0], npw[2*(n-1)]=pw[1];
else npw[1]=pw[1], npw[2*(n-1)]=pw[0];
pw=npw;
}
for (int j=0; j<2*n; j++)
{
if (pw[j]==p[0])
{
if (j/2<=res) res=j/2, st=(i/2)+1;
}
}
}
cout<<st;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |