# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
824074 |
2023-08-13T13:04:35 Z |
Khizri |
Scales (IOI15_scales) |
C++17 |
|
5 ms |
5464 KB |
#include "scales.h"
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
const int mxn=2e5+5;
vector<vector<int>>vt[mxn];
int L[mxn],R[mxn],M[mxn],iq[mxn],jq[mxn],kq[mxn],op[mxn],nxt=1;
void build(int node){
ll mx=INF;
int ix,jx,kx;
for(int i=0;i<6;i++){
for(int j=i+1;j<6;j++){
for(int k=j+1;k<6;k++){
ll a=0,b=0,c=0;
for(int idx=0;idx<vt[node].size();idx++){
if(vt[node][idx][i]>max(vt[node][idx][j],vt[node][idx][k])){
a++;
}
else if(vt[node][idx][j]>max(vt[node][idx][i],vt[node][idx][k])){
b++;
}
else{
c++;
}
}
if(max(a,max(b,c))<mx){
mx=max(a,max(b,c));
op[node]=1;
ix=i,jx=j,kx=k;
}
}
}
}
for(int i=0;i<6;i++){
for(int j=i+1;j<6;j++){
for(int k=j+1;k<6;k++){
ll a=0,b=0,c=0;
for(int idx=0;idx<vt[node].size();idx++){
if(vt[node][idx][i]<min(vt[node][idx][j],vt[node][idx][k])){
a++;
}
else if(vt[node][idx][j]<min(vt[node][idx][i],vt[node][idx][k])){
b++;
}
else{
c++;
}
}
if(max(a,max(b,c))<mx){
mx=max(a,max(b,c));
op[node]=0;
ix=i,jx=j,kx=k;
}
}
}
}
L[node]=++nxt;
M[node]=++nxt;
R[node]=++nxt;
iq[node]=ix;
jq[node]=jx;
kq[node]=kx;
if(op[node]==1){
for(int idx=0;idx<vt[node].size();idx++){
if(vt[node][idx][ix]>max(vt[node][idx][jx],vt[node][idx][kx])){
vt[L[node]].pb(vt[node][idx]);
}
else if(vt[node][idx][jx]>max(vt[node][idx][ix],vt[node][idx][kx])){
vt[M[node]].pb(vt[node][idx]);
}
else{
vt[R[node]].pb(vt[node][idx]);
}
}
}
else{
for(int idx=0;idx<vt[node].size();idx++){
if(vt[node][idx][ix]<min(vt[node][idx][jx],vt[node][idx][kx])){
vt[L[node]].pb(vt[node][idx]);
}
else if(vt[node][idx][jx]<min(vt[node][idx][ix],vt[node][idx][kx])){
vt[M[node]].pb(vt[node][idx]);
}
else{
vt[R[node]].pb(vt[node][idx]);
}
}
}
if(vt[L[node]].size()>1){
build(L[node]);
}
if(vt[M[node]].size()>1){
build(M[node]);
}
if(vt[R[node]].size()>1){
build(R[node]);
}
}
vector<int>query(int node){
if(vt[node].size()==1){
return vt[node][0];
}
int x;
if(op[node]==1){
x=getHeaviest(iq[node]+1,jq[node]+1,kq[node]+1);
}
else{
x=getLightest(iq[node]+1,jq[node]+1,kq[node]+1);
}
if(x==iq[node]+1){
return query(L[node]);
}
else if(x==jq[node]+1){
return query(M[node]);
}
else{
return query(R[node]);
}
}
void init(int T) {
vector<int>v(6);
iota(all(v),1);
do{
vt[1].pb(v);
}while(next_permutation(all(v)));
build(1);
}
void orderCoins() {
vector<int>vt=query(1);
int arr[6];
for(int i=0;i<6;i++){
arr[vt[i]-1]=i+1;
}
answer(arr);
}
/*
g++ scales.cpp grader.cpp ; .\a.exe
*/
Compilation message
scales.cpp: In function 'void build(int)':
scales.cpp:26:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int idx=0;idx<vt[node].size();idx++){
| ~~~^~~~~~~~~~~~~~~~
scales.cpp:49:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int idx=0;idx<vt[node].size();idx++){
| ~~~^~~~~~~~~~~~~~~~
scales.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int idx=0;idx<vt[node].size();idx++){
| ~~~^~~~~~~~~~~~~~~~
scales.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int idx=0;idx<vt[node].size();idx++){
| ~~~^~~~~~~~~~~~~~~~
scales.cpp: In function 'void init(int)':
scales.cpp:131:15: warning: unused parameter 'T' [-Wunused-parameter]
131 | void init(int T) {
| ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:141:16: warning: declaration of 'vt' shadows a global declaration [-Wshadow]
141 | vector<int>vt=query(1);
| ^~
scales.cpp:17:20: note: shadowed declaration is here
17 | vector<vector<int>>vt[mxn];
| ^~
scales.cpp: In function 'void build(int)':
scales.cpp:76:72: warning: 'kx' may be used uninitialized in this function [-Wmaybe-uninitialized]
76 | if(vt[node][idx][ix]>max(vt[node][idx][jx],vt[node][idx][kx])){
| ^
scales.cpp:76:54: warning: 'jx' may be used uninitialized in this function [-Wmaybe-uninitialized]
76 | if(vt[node][idx][ix]>max(vt[node][idx][jx],vt[node][idx][kx])){
| ^
scales.cpp:76:32: warning: 'ix' may be used uninitialized in this function [-Wmaybe-uninitialized]
76 | if(vt[node][idx][ix]>max(vt[node][idx][jx],vt[node][idx][kx])){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
2 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
3 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
4 |
Partially correct |
4 ms |
5384 KB |
Output is partially correct |
5 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
6 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
7 |
Partially correct |
3 ms |
5460 KB |
Output is partially correct |
8 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
9 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
10 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
11 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
12 |
Partially correct |
5 ms |
5460 KB |
Output is partially correct |
13 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
14 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
15 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
16 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
17 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
18 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
19 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
20 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
21 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
22 |
Partially correct |
5 ms |
5460 KB |
Output is partially correct |
23 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
24 |
Partially correct |
4 ms |
5412 KB |
Output is partially correct |
25 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
26 |
Partially correct |
5 ms |
5388 KB |
Output is partially correct |
27 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
28 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
29 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
30 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
31 |
Partially correct |
3 ms |
5460 KB |
Output is partially correct |
32 |
Partially correct |
4 ms |
5384 KB |
Output is partially correct |
33 |
Partially correct |
4 ms |
5412 KB |
Output is partially correct |
34 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
35 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
36 |
Partially correct |
4 ms |
5388 KB |
Output is partially correct |
37 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |
38 |
Partially correct |
4 ms |
5416 KB |
Output is partially correct |
39 |
Partially correct |
4 ms |
5464 KB |
Output is partially correct |
40 |
Partially correct |
4 ms |
5460 KB |
Output is partially correct |