답안 #199978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199978 2020-02-04T15:39:02 Z Mercenary 저울 (IOI15_scales) C++14
0 / 100
1000 ms 187384 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<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[x].size() <= 1)return 0;
    if(pos == 6)return 10;
    pair<int,int> res = mp(11 , 0);
    for(int i = 0 ; i < (int)query.size() ; ++i){
        auto tmp = Get(p[x] , i);
        int cnt = 0;
        for(int j = 0 ; j < 3 ; ++j){
            cnt += tmp[j].size() <= lim[pos];
        }
        if(cnt != 3)continue;
        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){
        int *ans = new int[6];
        for(int i = 0; i < 6; i++) ans[perm[p[x][0]][i]] = i + 1;
        #ifndef LOCAL
        answer(ans);
        #endif // LOCAL
        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));
            }
        }
    }
//    cout << query.size() << endl;
    build(0,0);
}

void orderCoins() {
    go(0);
}

#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:17: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:17:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetLig(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:21: note: shadowed declaration is here
 vector<vector<int>> p(1);
                     ^
scales.cpp: In function 'std::vector<std::vector<int> > GetHea(std::vector<int>&, std::vector<int>&)':
scales.cpp:29: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:29:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetHea(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:21: note: shadowed declaration is here
 vector<vector<int>> p(1);
                     ^
scales.cpp: In function 'std::vector<std::vector<int> > GetMed(std::vector<int>&, std::vector<int>&)':
scales.cpp:41: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:41:60: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> GetMed(vector<int> & p , vector<int> &a){
                                                            ^
scales.cpp:11:21: note: shadowed declaration is here
 vector<vector<int>> p(1);
                     ^
scales.cpp: In function 'std::vector<std::vector<int> > Get(std::vector<int>&, int)':
scales.cpp:54:47: warning: declaration of 'p' shadows a global declaration [-Wshadow]
 vector<vector<int>> Get(vector<int> &p , int q){
                                               ^
scales.cpp:11:21: note: shadowed declaration is here
 vector<vector<int>> p(1);
                     ^
scales.cpp: In function 'int build(int, int)':
scales.cpp:68:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             cnt += tmp[j].size() <= lim[pos];
scales.cpp:71:24: warning: conversion to 'int' from 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' may alter its value [-Wconversion]
         int sz = p.size();
                  ~~~~~~^~
scales.cpp:73:13: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
         int ans = 0;
             ^~~
scales.cpp:15:5: note: shadowed declaration is here
 int ans[maxn];
     ^~~
scales.cpp: In function 'void go(int)':
scales.cpp:85:14: warning: declaration of 'ans' shadows a global declaration [-Wshadow]
         int *ans = new int[6];
              ^~~
scales.cpp:15:5: note: shadowed declaration is here
 int ans[maxn];
     ^~~
scales.cpp: In function 'void init(int)':
scales.cpp:115:25: warning: declaration of 'tmp' shadows a previous local [-Wshadow]
             vector<int> tmp;
                         ^~~
scales.cpp:108:17: note: shadowed declaration is here
     vector<int> tmp(6);iota(tmp.begin(),tmp.end(),0);
                 ^~~
scales.cpp:107:15: warning: unused parameter 'T' [-Wunused-parameter]
 void init(int T) {
               ^
scales.cpp: In function 'std::vector<std::vector<int> > Get(std::vector<int>&, int)':
scales.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
scales.cpp: In function 'int build(int, int)':
scales.cpp:81:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
scales.cpp: In function 'void go(int)':
scales.cpp:98:5: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
     --id;
     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1103 ms 173984 KB Time limit exceeded
2 Execution timed out 1099 ms 179704 KB Time limit exceeded
3 Execution timed out 1102 ms 181704 KB Time limit exceeded
4 Execution timed out 1101 ms 180984 KB Time limit exceeded
5 Execution timed out 1105 ms 184576 KB Time limit exceeded
6 Execution timed out 1106 ms 182908 KB Time limit exceeded
7 Execution timed out 1094 ms 173348 KB Time limit exceeded
8 Execution timed out 1107 ms 185080 KB Time limit exceeded
9 Execution timed out 1105 ms 182648 KB Time limit exceeded
10 Execution timed out 1095 ms 180728 KB Time limit exceeded
11 Execution timed out 1102 ms 180216 KB Time limit exceeded
12 Execution timed out 1107 ms 184700 KB Time limit exceeded
13 Execution timed out 1103 ms 180860 KB Time limit exceeded
14 Execution timed out 1106 ms 180988 KB Time limit exceeded
15 Execution timed out 1102 ms 168028 KB Time limit exceeded
16 Execution timed out 1105 ms 176504 KB Time limit exceeded
17 Execution timed out 1097 ms 178552 KB Time limit exceeded
18 Execution timed out 1106 ms 180472 KB Time limit exceeded
19 Execution timed out 1090 ms 169456 KB Time limit exceeded
20 Execution timed out 1104 ms 182776 KB Time limit exceeded
21 Execution timed out 1103 ms 180472 KB Time limit exceeded
22 Execution timed out 1098 ms 181408 KB Time limit exceeded
23 Execution timed out 1104 ms 173560 KB Time limit exceeded
24 Execution timed out 1094 ms 178636 KB Time limit exceeded
25 Execution timed out 1098 ms 174328 KB Time limit exceeded
26 Execution timed out 1105 ms 183928 KB Time limit exceeded
27 Execution timed out 1104 ms 182264 KB Time limit exceeded
28 Execution timed out 1100 ms 180996 KB Time limit exceeded
29 Execution timed out 1105 ms 182268 KB Time limit exceeded
30 Execution timed out 1102 ms 181880 KB Time limit exceeded
31 Execution timed out 1101 ms 175724 KB Time limit exceeded
32 Execution timed out 1102 ms 181396 KB Time limit exceeded
33 Execution timed out 1094 ms 179836 KB Time limit exceeded
34 Execution timed out 1101 ms 175992 KB Time limit exceeded
35 Execution timed out 1107 ms 180728 KB Time limit exceeded
36 Execution timed out 1103 ms 186616 KB Time limit exceeded
37 Execution timed out 1106 ms 187384 KB Time limit exceeded
38 Execution timed out 1092 ms 181640 KB Time limit exceeded
39 Execution timed out 1099 ms 182592 KB Time limit exceeded
40 Execution timed out 1104 ms 185252 KB Time limit exceeded