답안 #240769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240769 2020-06-21T07:07:33 Z VEGAnn Zagonetka (COI18_zagonetka) C++14
0 / 100
69 ms 400 KB
#include <bits/stdc++.h>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
const int N = 110;
priority_queue<int, vector<int>, greater<int> > mn, mx;
vector<int> g[N], gr[N], vc;
int n, p[N], in[N], out[N];

void Final(){
    assert(sz(vc) == n);

    for (int cr : vc) {
        cout << cr;

        if (cr == vc.back())
            cout << endl;
        else cout << " ";
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
//    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> p[i];

    for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++){
        swap(p[i], p[j]);

        cout << "query";

        for (int i = 1; i <= n; i++)
            cout << " " << p[i];
        cout << endl;

        int res; cin >> res;

        swap(p[i], p[j]);

        if (res == 0){
            if (p[i] > p[j]) {
                g[j].PB(i);
                gr[i].PB(j);

                out[j]++;
                in[i]++;
            } else {
                g[i].PB(j);
                gr[j].PB(i);

                out[i]++;
                in[j]++;
            }
        }
    }

    vc.resize(n);

    for (int i = 1; i <= n; i++)
        if (in[i] == 0)
            mn.push(i);

    int ite = 0;

    while (sz(mn) > 0){
        int v = mn.top();
        mn.pop();

        vc[v - 1] = ++ite;

        for (int u : g[v]){
            in[u]--;

            if (in[u] == 0)
                mn.push(u);
        }
    }

    cout << "end" << endl;

    Final();

    for (int i = 1; i <= n; i++)
        if (out[i] == 0)
            mx.push(i);

    ite = n;

    while (sz(mx) > 0){
        int v = mx.top();
        mx.pop();

        vc[v - 1] = ite--;

        for (int u : gr[v]){
            out[u]--;

            if (out[u] == 0)
                mx.push(u);
        }
    }

    Final();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 400 KB Output isn't correct
2 Halted 0 ms 0 KB -