# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
200000 |
2020-02-04T17:23:17 Z |
Mercenary |
Scales (IOI15_scales) |
C++14 |
|
75 ms |
640 KB |
#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
Compilation message
scales.cpp: In function 'std::vector<std::vector<int> > GetLig(std::vector<int>&, std::vector<int>&)':
scales.cpp:18:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
^
scales.cpp:13:5: note: shadowed declaration is here
int a[maxn] , b[maxn][3];
^
scales.cpp:18:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp: In function 'std::vector<std::vector<int> > GetHea(std::vector<int>&, std::vector<int>&)':
scales.cpp:30:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
^
scales.cpp:13:5: note: shadowed declaration is here
int a[maxn] , b[maxn][3];
^
scales.cpp:30:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp: In function 'std::vector<std::vector<int> > GetMed(std::vector<int>&, std::vector<int>&)':
scales.cpp:42:60: warning: declaration of 'a' shadows a global declaration [-Wshadow]
vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
^
scales.cpp:13:5: note: shadowed declaration is here
int a[maxn] , b[maxn][3];
^
scales.cpp:42:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp: In function 'std::vector<std::vector<int> > GetNexLig(std::vector<int>&, std::vector<int>&)':
scales.cpp:54:63: warning: declaration of 'a' shadows a global declaration [-Wshadow]
vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){
^
scales.cpp:13:5: note: shadowed declaration is here
int a[maxn] , b[maxn][3];
^
scales.cpp:54:63: warning: declaration of 'p' shadows a global declaration [-Wshadow]
vector<vector<int>> GetNexLig(vector<int> & p , vector<int> &a){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp: In function 'std::vector<std::vector<int> > Get(std::vector<int>&, int)':
scales.cpp:72:47: warning: declaration of 'p' shadows a global declaration [-Wshadow]
vector<vector<int>> Get(vector<int> &p , int q){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp: In function 'int build(std::vector<int>, int)':
scales.cpp:79:34: warning: declaration of 'p' shadows a global declaration [-Wshadow]
int build(vector<int> p , int pos){
^
scales.cpp:11:13: note: shadowed declaration is here
vector<int> p;
^
scales.cpp:90:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
cnt += (tmp[j].size() <= lim[pos]);
scales.cpp: In function 'void init(int)':
scales.cpp:145:25: warning: declaration of 'tmp' shadows a previous local [-Wshadow]
vector<int> tmp;
^~~
scales.cpp:138:17: note: shadowed declaration is here
vector<int> tmp(6);iota(tmp.begin(),tmp.end(),0);
^~~
scales.cpp:137:15: warning: unused parameter 'T' [-Wunused-parameter]
void init(int T) {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
452 KB |
Output is correct |
2 |
Correct |
61 ms |
376 KB |
Output is correct |
3 |
Correct |
65 ms |
380 KB |
Output is correct |
4 |
Correct |
65 ms |
376 KB |
Output is correct |
5 |
Correct |
61 ms |
376 KB |
Output is correct |
6 |
Correct |
62 ms |
480 KB |
Output is correct |
7 |
Correct |
61 ms |
452 KB |
Output is correct |
8 |
Correct |
61 ms |
376 KB |
Output is correct |
9 |
Correct |
61 ms |
376 KB |
Output is correct |
10 |
Correct |
64 ms |
508 KB |
Output is correct |
11 |
Correct |
63 ms |
376 KB |
Output is correct |
12 |
Correct |
60 ms |
376 KB |
Output is correct |
13 |
Correct |
61 ms |
376 KB |
Output is correct |
14 |
Correct |
62 ms |
376 KB |
Output is correct |
15 |
Correct |
60 ms |
376 KB |
Output is correct |
16 |
Correct |
62 ms |
376 KB |
Output is correct |
17 |
Correct |
62 ms |
376 KB |
Output is correct |
18 |
Correct |
60 ms |
376 KB |
Output is correct |
19 |
Correct |
61 ms |
376 KB |
Output is correct |
20 |
Correct |
61 ms |
376 KB |
Output is correct |
21 |
Correct |
62 ms |
376 KB |
Output is correct |
22 |
Correct |
64 ms |
632 KB |
Output is correct |
23 |
Correct |
60 ms |
376 KB |
Output is correct |
24 |
Correct |
63 ms |
380 KB |
Output is correct |
25 |
Correct |
61 ms |
380 KB |
Output is correct |
26 |
Correct |
60 ms |
376 KB |
Output is correct |
27 |
Correct |
62 ms |
376 KB |
Output is correct |
28 |
Correct |
62 ms |
520 KB |
Output is correct |
29 |
Correct |
61 ms |
376 KB |
Output is correct |
30 |
Correct |
61 ms |
376 KB |
Output is correct |
31 |
Correct |
62 ms |
376 KB |
Output is correct |
32 |
Correct |
63 ms |
376 KB |
Output is correct |
33 |
Correct |
64 ms |
468 KB |
Output is correct |
34 |
Correct |
62 ms |
640 KB |
Output is correct |
35 |
Correct |
75 ms |
376 KB |
Output is correct |
36 |
Correct |
61 ms |
376 KB |
Output is correct |
37 |
Correct |
62 ms |
376 KB |
Output is correct |
38 |
Correct |
61 ms |
504 KB |
Output is correct |
39 |
Correct |
63 ms |
504 KB |
Output is correct |
40 |
Correct |
61 ms |
376 KB |
Output is correct |