Submission #967142

# Submission time Handle Problem Language Result Execution time Memory
967142 2024-04-21T09:54:23 Z Lukap Zagonetka (COI18_zagonetka) C++14
27 / 100
64 ms 1272 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 107;

int n;
int niz[MAXN];
vector<int> ind, v, rod[MAXN], djeca[MAXN];
vector<pair<int, int> > pravila;
int preb[MAXN], bio[MAXN], ispis[MAXN];

bool cmp (int a, int b) {
    return niz[a] < niz[b];
}

bool dobro (int x) {
//    cout << x << ' ' << preb[x] << "\n";
    bio[x] = 1;
    if (preb[x]) return false;

    for (auto nx: rod[x]) {
        if (!bio[nx]) {
            if (!dobro (nx)) return false;
        }
    }
    return true;
}

bool pitaj (int x, int y) {
    int novi_niz[MAXN];

    for (int i = 0; i < n; i++) novi_niz[i] = niz[i];

    for (int i = 0; i < n; i++) preb[i] = 0;
    for (int i = 0; i < n; i++) bio[i] = 0;
    preb[ind[x]] = 1;

//    cout << "KOJI " << x + 1 << ' ' << y + 1 << "\n";

    for (int i = x + 1; i < y; i++) {
        if (!dobro (ind[i])) preb[ind[i]] = 1;
    }

    if (!dobro (ind[y])) return false;

    v.clear ();
    for (int i = x; i <= y; i++) {
        if (!preb[ind[i]]) v.push_back (i);
    }
    for (int i = x; i <= y; i++) {
        if (preb[ind[i]]) v.push_back (i);
    }

//    for (int i = 0; i < n; i++) cout << preb[i] << ' ';
//    cout << "\n";

    for (int i = x; i <= y; i++) novi_niz[ind[v[i - x]]] = i + 1;

    cout << "query ";
    for (int i = 0; i < n; i++) cout << novi_niz[i] << ' ';
    cout << endl;
    int a;
    cin >> a;

    if (a) return true;
    else return false;
}

void gore (int x) {
    bio[x] = 1;
    for (auto nx: rod[x]) {
        if (!bio[nx]) gore (nx);
    }

    v.push_back (x);
}

void dole (int x) {
    bio[x] = 1;
    for (auto nx: djeca[x]) {
        if (!bio[nx]) dole (nx);
    }

    v.push_back (x);
}

int main () {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> niz[i];
    for (int i = 0; i < n; i++) ind.push_back (i);
    sort (ind.begin (), ind.end (), cmp);

    for (int i = 1; i < n; i++) {
        for (int j = i - 1; j >= 0; j--) {
            if (!pitaj (j, i)) {
                pravila.push_back ({ind[j], ind[i]});
                rod[ind[i]].push_back (ind[j]);
                djeca[ind[j]].push_back (ind[i]);
            }
        }
    }
    cout << "end" << endl;

    for (int i = 0; i < n; i++) sort (rod[i].begin (), rod[i].end ());
    v.clear ();
    memset (bio, 0, sizeof (bio));
    for (int i = 0; i < n; i++) {
        if (!bio[i]) gore (i);
    }
    for (int i = 0; i < n; i++) ispis[v[i]] = i + 1;
    for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
    cout << endl;



    for (int i = 0; i < n; i++) sort (djeca[i].begin (), djeca[i].end ());
    v.clear ();
    memset (bio, 0, sizeof (bio));
    for (int i = 0; i < n; i++) {
        if (!bio[i]) dole (i);
    }
    for (int  i = 0; i < n; i++) ispis[v[i]] = n - i;
    for (int i = 0; i < n; i++) cout << ispis[i] << ' ';
    cout << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 15 ms 344 KB Output is correct
3 Correct 18 ms 344 KB Output is correct
4 Correct 18 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 18 ms 340 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 15 ms 344 KB Output is correct
10 Correct 7 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 704 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 344 KB Output is correct
2 Correct 49 ms 344 KB Output is correct
3 Correct 37 ms 424 KB Output is correct
4 Correct 50 ms 748 KB Output is correct
5 Correct 63 ms 1272 KB Output is correct
6 Correct 61 ms 972 KB Output is correct
7 Correct 45 ms 756 KB Output is correct
8 Correct 51 ms 952 KB Output is correct
9 Correct 64 ms 756 KB Output is correct
10 Incorrect 53 ms 688 KB Output isn't correct
11 Halted 0 ms 0 KB -