# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831596 | waldi | Scales (IOI15_scales) | C++17 | 1 ms | 304 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>
#ifndef LOCAL
#include "scales.h"
#endif
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
using namespace std;
#ifdef LOCAL
vector<int> perm;
int getLightest(int a, int b, int c){
if(perm[a] < min(perm[b], perm[c])) return a;
if(perm[b] < min(perm[a], perm[c])) return b;
return c;
}
int getHeaviest(int a, int b, int c){
if(perm[a] > max(perm[b], perm[c])) return a;
if(perm[b] > max(perm[a], perm[c])) return b;
return c;
}
int getMedian(int a, int b, int c){
int x = getLightest(a, b, c);
int y = getHeaviest(a, b, c);
if(a!=x && a!=y) return a;
if(b!=x && b!=y) return b;
return c;
}
int getNextLightest(int a, int b, int c, int d){
vector<int> wieksze;
if(perm[a] > perm[d]) wieksze.emplace_back(a);
if(perm[b] > perm[d]) wieksze.emplace_back(b);
if(perm[c] > perm[d]) wieksze.emplace_back(c);
if(wieksze.size() == 1) return wieksze[0];
if(wieksze.size() == 2) return perm[wieksze[0]] < perm[wieksze[1]] ? wieksze[0] : wieksze[1];
return getLightest(a, b, c);
}
void answer(int wyn[]){
REP(i, 6-1) if(perm[wyn[i]] > perm[wyn[i+1]]){
FOR(x, 1, 6) printf("%d ", perm[x]);
printf("\n");
REP(x, 6) printf("%d ", wyn[x]);
printf("\ndupa\n");
exit(1);
}
}
#endif
void init(int t){
}
vector<int> posortuj4(vector<int> vec){
int med = getMedian(vec[0], vec[1], vec[2]);
if(med == vec[0]) swap(vec[0], vec[1]);
if(med == vec[2]) swap(vec[2], vec[1]);
// vec = {?, 2=med, ?, ?}
int maks = getHeaviest(vec[0], vec[2], vec[3]);
if(maks == vec[3]){
int mini = getLightest(vec[0], vec[1], vec[2]);
if(mini == vec[2]) swap(vec[0], vec[2]);
return vec;
}
if(maks == vec[0]) swap(vec[0], vec[2]);
// vec = {1, 2=med, 3, ?}
int t = getNextLightest(vec[0], vec[1], vec[2], vec[3]);
swap(vec[2], vec[3]);
if(t == vec[3]) return vec;
swap(vec[1], vec[2]);
if(t == vec[2]) return vec;
swap(vec[0], vec[1]);
return vec;
}
void orderCoins(){
vector<int> male = {1, 2, 3};
swap(male[0], male[getLightest(1, 2, 3)-1]);
// male = {1, ?, ?}
vector<int> duze = {4, 5, 6};
swap(duze[2], duze[getHeaviest(4, 5, 6)-4]);
// duze = {?, ?, 3}
int mini = getLightest(male[0], duze[0], duze[1]);// minimum wszystkiego
int maks = getHeaviest(male[1], male[2], duze[2]);// maksimum wszystkiego
vector<int> vec;
FOR(i, 1, 6) if(i != mini && i != maks) vec.emplace_back(i);
// vec - wszystko bez minimum i maksimum
vec = posortuj4(vec);
int wyn[] = {mini, vec[0], vec[1], vec[2], vec[3], maks};
answer(wyn);
}
#ifdef LOCAL
int main(){
perm = {69, 1, 2, 3, 4, 5, 6};
do{
orderCoins();
} while(next_permutation(perm.begin()+1, perm.end()));
}
#endif
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |