# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
584822 | krit3379 | Scales (IOI15_scales) | C++17 | 138 ms | 468 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.
#include<bits/stdc++.h>
#include "scales.h"
using namespace std;
#define N 100005
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
struct A{
int id,i,j,k,l;
}upd;
vector<vector<int>> per;
vector<int> v;
void init(int t){
v={0,1,2,3,4,5};
do{
per.push_back(v);
}while(next_permutation(v.begin(),v.end()));
}
void orderCoins(){
int ma,m,m1,m2,i,j,k,l,a,b,c,d,c1,c2,c3,x;
int ans[6];
vector<vector<int>> now=per,temp;
while(now.size()>1){
ma=2e9;
//case 1
for(i=0;i<6;i++)for(j=i+1;j<6;j++)for(k=j+1;k<6;k++){
c1=c2=c3=0;
for(auto arr:now){
a=arr[i],b=arr[j],c=arr[k];
m=max({a,b,c});
if(m==a)c1++;
else if(m==b)c2++;
else c3++;
}
if(max({c1,c2,c3})<=ma)ma=max({c1,c2,c3}),upd={1,i,j,k};
}
//case 2
for(i=0;i<6;i++)for(j=i+1;j<6;j++)for(k=j+1;k<6;k++){
c1=c2=c3=0;
for(auto arr:now){
a=arr[i],b=arr[j],c=arr[k];
m=min({a,b,c});
if(m==a)c1++;
else if(m==b)c2++;
else c3++;
}
if(max({c1,c2,c3})<=ma)ma=max({c1,c2,c3}),upd={2,i,j,k};
}
//case 3
for(i=0;i<6;i++)for(j=i+1;j<6;j++)for(k=j+1;k<6;k++){
c1=c2=c3=0;
for(auto arr:now){
a=arr[i],b=arr[j],c=arr[k];
m1=min({a,b,c});
m2=max({a,b,c});
if(a!=m1&&a!=m2)c1++;
else if(b!=m1&&b!=m2)c2++;
else c3++;
}
if(max({c1,c2,c3})<=ma)ma=max({c1,c2,c3}),upd={3,i,j,k};
}
//case 4
for(i=0;i<6;i++)for(j=i+1;j<6;j++)for(k=j+1;k<6;k++)for(l=0;l<6;l++){
if(l==i||l==j||l==k)continue;
c1=c2=c3=0;
for(auto arr:now){
a=arr[i],b=arr[j],c=arr[k],d=arr[l];
vector<int> t={a,b,c};
sort(t.begin(),t.end());
if(arr[l]>t[2]||arr[l]<t[0]){
if(a==t[0])c1++;
else if(b==t[0])c2++;
else c3++;
}
else if(arr[l]<t[1]){
if(a==t[1])c1++;
else if(b==t[1])c2++;
else c3++;
}
else{
if(a==t[2])c1++;
else if(b==t[2])c2++;
else c3++;
}
}
if(max({c1,c2,c3})<=ma)ma=max({c1,c2,c3}),upd={4,i,j,k,l};
}
auto [op,i,j,k,l]=upd;
if(op==1){
x=getHeaviest(i+1,j+1,k+1);
x--;
for(auto arr:now)if(arr[x]==max({arr[i],arr[j],arr[k]}))temp.push_back(arr);
}
else if(op==2){
x=getLightest(i+1,j+1,k+1);
x--;
for(auto arr:now)if(arr[x]==min({arr[i],arr[j],arr[k]}))temp.push_back(arr);
}
else if(op==3){
x=getMedian(i+1,j+1,k+1);
x--;
for(auto arr:now)if(arr[x]!=max({arr[i],arr[j],arr[k]})&&arr[x]!=min({arr[i],arr[j],arr[k]}))temp.push_back(arr);
}
else{
x=getNextLightest(i+1,j+1,k+1,l+1);
x--;
int sz=0;
for(auto arr:now){
int t=1e9;
if(arr[i]>arr[l])t=min(t,arr[i]);
if(arr[j]>arr[l])t=min(t,arr[j]);
if(arr[k]>arr[l])t=min(t,arr[k]);
if((max({arr[i],arr[j],arr[k]})<arr[l]&&arr[x]==min({arr[i],arr[j],arr[k]}))||arr[x]==t)temp.push_back(arr);
}
}
now=temp;
temp.clear();
}
for(i=0;i<6;i++)ans[now[0][i]]=i+1;
answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |