제출 #824074

#제출 시각아이디문제언어결과실행 시간메모리
824074Khizri저울 (IOI15_scales)C++17
55.56 / 100
5 ms5464 KiB
#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 */

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...