# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210831 | tleontest1 | Studentsko (COCI14_studentsko) | C++14 | 1070 ms | 1016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
map<int,int> mpp,vis;
vector<int> v;
int main(void){
scanf("%d %d",&n,&m);
FOR{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(b+1,b+n+1);
FOR{
mpp[b[i]]=(i-1)/m+1;
}
//~ int say=0;
for(int i=1;i<=n/m;i++){
for(int j=1;j<=n;j++){
if(mpp[a[j]]==i){v.pb(a[j]);}
}
}
FOR{
b[i]=a[i];
vis[a[i]]=i;
}
for(int i=1;i<=n;i++){
int bas=vis[v[i-1]];
flag=0;
for(int j=bas;j>i;j--){
vis[b[j-1]]=j;
vis[b[j]]=j-1;
swap(b[j],b[j-1]);
flag=1;
}
for(int j=bas;j<i;j++){
vis[b[j+1]]=j;
vis[b[j]]=j+1;
swap(b[j],b[j+1]);
flag=1;
}
if(flag)
cev++;
}
int mn=cev;
cev=0;
FOR{
b[i]=a[i];
vis[a[i]]=i;
}
for(int i=n;i>=1;i--){
flag=0;
int bas=vis[v[i-1]];
for(int j=bas;j>i;j--){
vis[b[j-1]]=j;
vis[b[j]]=j-1;
swap(b[j],b[j-1]);
flag=1;
}
for(int j=bas;j<i;j++){
vis[b[j+1]]=j;
vis[b[j]]=j+1;
swap(b[j],b[j+1]);
flag=1;
}
if(flag)
cev++;
}
printf("%d\n",min(mn,cev));
return 0;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |