제출 #1333336

#제출 시각아이디문제언어결과실행 시간메모리
1333336kawhiet저울 (IOI15_scales)C++20
46.02 / 100
1 ms360 KiB
#include <bits/stdc++.h>
#include "scales.h"

#ifdef LOCAL
#include "graderlib.c"
#endif

using namespace std;

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

void ans(int a, int b, int c, int d, int e, int f) {
    int w[] = {a, b, c, d, e, f};
    answer(w);
}

void ans(vector<int> w) {
    int ret[6];
    for (int i = 0; i < 6; i++) {
        ret[i] = w[i];
    }
    answer(ret);
}

vector<int> topsort(vector<vector<int>> &g) {
    int n = 7;
    vector<int> in(n);
    for (int i = 1; i < n; i++) {
        for (auto j : g[i]) {
            // cerr << i << ' ' << j << '\n';
            in[j]++;
        }
    }
    queue<int> q;
    for (int i = 1; i < n; i++) {
        if (in[i] == 0) {
            q.push(i);
        }
    }
    vector<int> ret;
    while (!q.empty()) {
        int u = q.front();
        ret.push_back(u);
        q.pop();
        for (auto v : g[u]) {
            if (--in[v] == 0) {
                q.push(v);
            }
        }
    }
    return ret;
}

void orderCoins() {
    /* ... */
    int a = getLightest(1, 2, 3);
    int b = getMedian(1, 2, 3);
    int c = 6 - a - b;
    int d = getLightest(4, 5, 6);
    int e = getMedian(4, 5, 6);
    int f = 15 - d - e;
    int x = getNextLightest(a, b, c, d);
    int y = getNextLightest(a, b, c, e);
    int z = getNextLightest(a, b, c, f);
    if (x == a && y == a && z == a) {
        int k = getNextLightest(d, e, f, a);
        if (k == d) {
            int m = getHeaviest(f, c, e);
            if (m == f) {
                ans(a, b, c, d, e, f);
            } else {
                ans(d, e, f, a, b, c);
            }
        } else {
            if (k == e) {
                ans(d, a, b, c, e, f);
            } else {
                ans(d, e, a, b, c, f);
            }
        }
    } else {
        // cout << a << ' ' << b << ' ' << c << '\n';
        // cout << d << ' ' << e << ' ' << f << '\n';
        // cout << x << ' ' << y << ' ' << z << '\n';
        vector<vector<int>> g(7);
        g[a].push_back(b);
        g[b].push_back(c);
        g[d].push_back(e);
        g[e].push_back(f);
        g[d].push_back(x);
        if (x == c) {
            g[b].push_back(d);
        } else if (x == b) {
            g[a].push_back(d);
        }
        if (y != a) {
            g[e].push_back(y);
            if (y == c) {
                g[b].push_back(e);
            } else {
                g[a].push_back(e);
            }
        } else {
            if (z != a) {
                g[e].push_back(y);
            } else {
                g[c].push_back(e);
            }
        }
        if (z != a) {
            g[f].push_back(c);
            g[f].push_back(z);
            if (z == c) {
                g[b].push_back(f);
            } else {
                g[a].push_back(f);
            }
        } else {
            g[c].push_back(f);
        }
        vector<int> r = topsort(g);
        ans(r);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...