# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
200000 | Mercenary | 저울 (IOI15_scales) | C++14 | 75 ms | 640 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<int> lim ={243,81,27,9,3,1};
vector<int> p;
int a[maxn] , b[maxn][3];
int root , nTime = 0;
vector<pair<int,vector<int>>> query;
vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0);
for(auto & c : p){
sort(tmp.begin(),tmp.end(),[&](const int x , const int y){
return perm[c][a[x]] < perm[c][a[y]];
});
res[tmp[0]].pb(c);
}
return res;
}
vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0);
for(auto & c : p){
sort(tmp.begin(),tmp.end(),[&](const int x , const int y){
return perm[c][a[x]] < perm[c][a[y]];
});
res[tmp[2]].pb(c);
}
return res;
}
vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0);
for(auto & c : p){
sort(tmp.begin(),tmp.end(),[&](const int x , const int y){
return perm[c][a[x]] < perm[c][a[y]];
});
res[tmp[1]].pb(c);
}
return res;
}
vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){
vector<vector<int>> res(3);
vector<int> tmp(3);iota(tmp.begin(),tmp.end(),0);
for(auto & c : p){
sort(tmp.begin(),tmp.end(),[&](const int x , const int y){
return perm[c][a[x]] < perm[c][a[y]];
});
if(perm[c][a[tmp[2]]] <= perm[c][a[3]]){
res[tmp[0]].pb(c);
}else if(perm[c][a[tmp[0]]] > perm[c][a[3]]){
res[tmp[0]].pb(c);
}else if(perm[c][a[tmp[1]]] > perm[c][a[3]]){
res[tmp[1]].pb(c);
}else res[tmp[2]].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);
return GetNexLig(p,query[q].second);
}
int build(vector<int> p , int pos){
if(p.size() <= 1){
b[++nTime][0] = -1;
// assert(p.size());
a[nTime] = (p.size() ? p[0] : 0);
return nTime;
}
for(int i = 0 ; i < (int)query.size() ; ++i){
auto tmp = Get(p , i);
int cnt = 0;
for(int j = 0 ; j < 3 ; ++j){
cnt += (tmp[j].size() <= lim[pos]);
}
if(cnt < 3)continue;
bool ok = 1;
int tmpb[3];
for(int j = 0 ; j < 3 ; ++j){
int tmp1 = build(tmp[j],pos+1);
if(!tmp1){
ok = 0;
break;
};
tmpb[j] = tmp1;
}
if(ok){
++nTime;
a[nTime] = i;
for(int j = 0 ; j < 3 ; ++j)b[nTime][j] = tmpb[j];
return nTime;
}
}
return 0;
}
void go(int x){
if(b[x][0] == -1){
int *ans = new int[6];
for(int i = 0; i < 6; i++) ans[perm[a[x]][i]] = i + 1;
#ifndef LOCAL
answer(ans);
#endif // LOCAL
return;
}
auto q = query[a[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);
else id = getNextLightest(q.second[0]+1,q.second[1]+1,q.second[2]+1,q.second[3]+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.resize(perm.size());iota(p.begin(),p.end(),0);
for(int i = 0 ; i < (1 << 6) ; ++i){
if(__builtin_popcount(i) == 3){
vector<int> tmp;
for(int j = 0 ; j < 6 ; ++j){
if(i & (1 << j))tmp.pb(j);
}
for(int j = 0 ; j < 3 ; ++j){
query.pb(mp(j,tmp));
}
for(int j = 0 ; j < 6; ++j){
auto tmp1 = tmp;tmp1.pb(j);
query.pb(mp(3,tmp1));
}
}
}
root = build(p,0);
}
void orderCoins() {
go(root);
}
#ifdef LOCAL
int main(){
init(0);
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |