# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199975 | Mercenary | Scales (IOI15_scales) | C++14 | 1117 ms | 211272 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>
using namespace std;
#include"scales.h"
#define mp make_pair
#define pb push_back
const int maxn = 2e6;
vector<vector<int>> perm;
vector<vector<int>> p(1);
int a[maxn] , b[maxn][3];
vector<pair<int,vector<int>>> query;
int ans[maxn];
vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
for(int i = 0 ; i < 3 ; ++i){
for(auto & c : p){
if(perm[c][a[i]] == min({perm[c][a[0]] , perm[c][a[1]] , perm[c][a[2]]})){
res[i].pb(c);
}
}
}
return res;
}
vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
for(int i = 0 ; i < 3 ; ++i){
for(auto & c : p){
if(perm[c][a[i]] == max({perm[c][a[0]] , perm[c][a[1]] , perm[c][a[2]]})){
res[i].pb(c);
}
}
}
return res;
}
vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
for(int i = 0 ; i < 3 ; ++i){
for(auto & c : p){
if(perm[c][a[i]] != min({perm[c][a[0]] , perm[c][a[1]] , perm[c][a[2]]}) &&
perm[c][a[i]] != max({perm[c][a[0]] , perm[c][a[1]] , perm[c][a[2]]})){
res[i].pb(c);
}
}
}
return res;
}
vector<vector<int>> Get(vector<int> &p , int q){
if(query[q].first == 0)return GetLig(p,query[q].second);
if(query[q].first == 1)return GetHea(p,query[q].second);
if(query[q].first == 2)return GetMed(p,query[q].second);
}
int build(int pos , int x){
if(p[pos].size() <= 1)return 0;
if(pos == 6)return 10;
pair<int,int> res = mp(6 , 0);
for(int i = 0 ; i < (int)query.size() ; ++i){
auto tmp = Get(p[x] , i);
int sz = p.size();
for(auto &c : tmp)p.pb(c);
int ans = 0;
for(int j = 0 ; j < 3 ; ++j){
b[x][j] = sz + j;
ans = max(ans,build(pos+1,sz+j));
}
res = min(res,mp(ans,i));
}
ans[x] = res.second;
}
void go(int x){
if(p[x].size() == 1 || 1){
int *ans = new int[6];
for(int i = 0; i < 6; i++) ans[perm[p[x][0]][i]] = i + 1;
answer(ans);
return;
}
auto q = query[ans[x]];
auto tmp = Get(p[x] , ans[x]);
int id;
if(q.first == 0)id = getLightest(q.second[0]+1,q.second[1]+1,q.second[2]+1);
else if(q.first == 1)id = getHeaviest(q.second[0]+1,q.second[1]+1,q.second[2]+1);
else if(q.first == 2)id = getMedian(q.second[0]+1,q.second[1]+1,q.second[2]+1);
--id;
for(int i = 0 ; i < 3 ; ++i){
if(q.second[i] == id){
go(b[x][i]);
return;
}
}
}
void init(int T) {
vector<int> tmp(6);iota(tmp.begin(),tmp.end(),0);
do{
perm.pb(tmp);
}while(next_permutation(tmp.begin(),tmp.end()));
p[0].resize(720);iota(p[0].begin(),p[0].end(),0);
for(int i = 0 ; i < (1 << 6) ; ++i){
if(__builtin_popcount(i) == 3){
vector<int> tmp;
for(int j = 0 ; j < 10 ; ++j){
if(i & (1 << j))tmp.pb(j);
}
for(int j = 0 ; j < 3 ; ++j){
query.pb(mp(j,tmp));
}
}
}
build(0,0);
}
void orderCoins() {
go(0);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |