Submission #276117

#TimeUsernameProblemLanguageResultExecution timeMemory
276117stoyan_malininScales (IOI15_scales)C++14
0 / 100
1 ms384 KiB
#include "scales.h"
//#include "grader.cpp"

#include <set>
#include <vector>
#include <iostream>

using namespace std;

struct Query
{
    int type;
    set <int> args;

    int ans;

    Query(){}
    Query(int type, set <int> args, int ans)
    {
        this->type = type;
        this->args = args;

        this->ans = ans;
    }
};

struct QueryKeeper
{
    vector <Query> v;

    int get(int ind)
    {
        return v[ind].ans;
    }
};

QueryKeeper welko;
int ask(int type, set <int> args)
{
    int a, b, c, d;
    auto it = args.begin();

    a = *it;it++;
    b = *it;it++;
    c = *it;it++;
    if(type==4) d = *it;

    int res;
    if(type==1) res = getHeaviest(a, b, c);
    else if(type==2) res = getLightest(a, b, c);
    else if(type==3) res = getMedian(a, b, c);
    else if(type==4) res = getNextLightest(a, b, c, d);

    welko.v.push_back(Query(type, args, res));
    return res;
}

set <int> exclude(set <int> s, vector <int> v)
{
    for(int x: v) s.erase(x);
    return s;
}

set <int> include(set <int> s, vector <int> v)
{
    for(int x: v) s.insert(x);
    return s;
}

void init(int T) {
    /* ... */
}

void solve4(set <int> s, int *W)
{
    vector <int> v;
    for(int x: s) v.push_back(x);

    int b = ask(1, {v[0], v[1], v[2]});
    W[1] = ask(2, exclude(s, {b}));

    int med = ask(3, exclude(s, {W[1]}));

    int c;
    if(v[3]!=W[1]) c = v[3];
    else c = *exclude(s, {b, W[1]}).begin();

    int a = *exclude(s, {b, c, W[1]}).begin();

    if(med==b) W[2] = a, W[3] = b, W[4] = c;
    else if(med==a) W[2] = c, W[3] = a, W[4] = b;
    else if(med==c) W[2] = a, W[3] = c, W[4] = b;

    //cout << a << " " << b << " " << c << '\n';
}

void orderCoins() {
    /* ... */
    int W[] = {-1, -1, -1, -1, -1, -1};

    ask(1, {1, 2, 3});
    ask(2, {4, 5, 6});
    ask(1, include(exclude({4, 5, 6}, {welko.get(1)}), {welko.get(0)}));
    ask(2, include(exclude({1, 2, 3}, {welko.get(0)}), {welko.get(1)}));

    W[5] = welko.get(2);
    W[0] = welko.get(3);

    set <int> rem = exclude({1, 2, 3, 4, 5, 6}, {welko.get(2), welko.get(3)});
    solve4(rem, W);

    answer(W);
}

Compilation message (stderr)

scales.cpp: In constructor 'Query::Query(int, std::set<int>, int)':
scales.cpp:19:5: warning: declaration of 'ans' shadows a member of 'Query' [-Wshadow]
   19 |     {
      |     ^
scales.cpp:15:9: note: shadowed declaration is here
   15 |     int ans;
      |         ^~~
scales.cpp:19:5: warning: declaration of 'args' shadows a member of 'Query' [-Wshadow]
   19 |     {
      |     ^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     set <int> args;
      |               ^~~~
scales.cpp:19:5: warning: declaration of 'type' shadows a member of 'Query' [-Wshadow]
   19 |     {
      |     ^
scales.cpp:12:9: note: shadowed declaration is here
   12 |     int type;
      |         ^~~~
scales.cpp: In constructor 'Query::Query(int, std::set<int>, int)':
scales.cpp:24:5: warning: declaration of 'ans' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:15:9: note: shadowed declaration is here
   15 |     int ans;
      |         ^~~
scales.cpp:24:5: warning: declaration of 'args' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     set <int> args;
      |               ^~~~
scales.cpp:24:5: warning: declaration of 'type' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:12:9: note: shadowed declaration is here
   12 |     int type;
      |         ^~~~
scales.cpp: In constructor 'Query::Query(int, std::set<int>, int)':
scales.cpp:24:5: warning: declaration of 'ans' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:15:9: note: shadowed declaration is here
   15 |     int ans;
      |         ^~~
scales.cpp:24:5: warning: declaration of 'args' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:13:15: note: shadowed declaration is here
   13 |     set <int> args;
      |               ^~~~
scales.cpp:24:5: warning: declaration of 'type' shadows a member of 'Query' [-Wshadow]
   24 |     }
      |     ^
scales.cpp:12:9: note: shadowed declaration is here
   12 |     int type;
      |         ^~~~
scales.cpp: In function 'void init(int)':
scales.cpp:70:15: warning: unused parameter 'T' [-Wunused-parameter]
   70 | void init(int T) {
      |           ~~~~^
scales.cpp: In function 'int ask(int, std::set<int>)':
scales.cpp:23:19: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   23 |         this->ans = ans;
      |         ~~~~~~~~~~^~~~~
scales.cpp:48:9: note: 'res' was declared here
   48 |     int res;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...