답안 #240797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240797 2020-06-21T08:07:19 Z VEGAnn Zagonetka (COI18_zagonetka) C++14
0 / 100
109 ms 504 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;
vector<int> g[N], gr[N], vc, lst, pos;
int n, p[N], in[N], c_in[N], loc[N], mem;
bool mrk[N];

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

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

bool ok(){
    pos.clear();

    for (int i = 0; i < n; i++){
        c_in[i] = in[i];

        if (in[i] == 0)
            pos.PB(i);
    }

    for (int it = 0, vl = 1; it < n; it++, vl++) {
        int fr = -1;

        if (mrk[vl]){
            bool was = 0;

            for (int i = 0; i < sz(pos); i++)
                if (pos[i] == loc[vl]){
                    fr = pos[i];
                    swap(pos.back(), pos[i]);
                    pos.pop_back();
                    was = 1;
                    break;
                }

            if (!was)
                return 0;
        } else {
            bool was = 0, fr = -1;

            for (int i = 0; i < sz(pos); i++)
                if (pos[i] > mem){
                    fr = pos[i];
                    swap(pos.back(), pos[i]);
                    pos.pop_back();
                    was = 1;
                    break;
                }

            if (!was)
                return 0;
        }

        for (int u : g[fr]){
            c_in[u]--;

            if (c_in[u] == 0)
                pos.PB(u);
        }
    }

    return 1;
}

void build(){
    fill(mrk, mrk + 0, 0);

    for (int it = 0; it < n; it++)
    for (int cr : lst){
        mem = it;

        mrk[cr] = 1;
        vc[it] = cr;
        loc[cr] = it;

        if (ok()){
            break;
        }

        mrk[cr] = 0;
    }
}

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);

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

                in[j]++;
            }
        }
    }

    cout << "end" << endl;

    vc.resize(n);

    for (int i = 1; i <= n; i++)
        lst.PB(i);

    build();

    Final();

    reverse(all(lst));

    build();

    Final();

    return 0;
}

Compilation message

zagonetka.cpp: In function 'bool ok()':
zagonetka.cpp:49:27: warning: variable 'fr' set but not used [-Wunused-but-set-variable]
             bool was = 0, fr = -1;
                           ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 109 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -