Submission #144817

# Submission time Handle Problem Language Result Execution time Memory
144817 2019-08-17T20:49:25 Z SamAnd Zagonetka (COI18_zagonetka) C++17
100 / 100
149 ms 632 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 102;

int n;

bool qry(int a[])
{
    cout << "query";
    for (int k = 1; k <= n; ++k)
        cout << ' ' << a[k];
    cout << endl;
    int x;
    cin >> x;
    return x;
}

int a[N];

int b[N];
vector<int> g[N];

int z;
bool c[N];
int u[N];
void dfs(int x)
{
    c[x] = true;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (!c[h])
            dfs(h);
    }
    u[x] = ++z;
}

set<int> s[N];
void dfs1(int x)
{
    c[x] = true;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        s[x].insert(h);
        if (!c[h])
            dfs1(h);
        for (set<int>::iterator it = s[h].begin(); it != s[h].end(); ++it)
            s[x].insert(*it);
    }
}

int minu[N];
void dfs2(int x)
{
    c[x] = true;
    sort(g[x].begin(), g[x].end());
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (!c[h])
            dfs2(h);
    }
    minu[x] = ++z;
}

vector<int> gg[N];
int maxu[N];
void dfs3(int x)
{
    c[x] = true;
    sort(gg[x].begin(), gg[x].end());
    for (int i = 0; i < gg[x].size(); ++i)
    {
        int h = gg[x][i];
        if (!c[h])
            dfs3(h);
    }
    maxu[x] = --z;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    for (int i = 1; i <= n; ++i)
    {
        b[a[i]] = i;
    }
    for (int i = 2; i <= n; ++i)
    {
        for (int j = i - 1; j >= 1; --j)
        {
            g[b[j]].push_back(b[i]);
            for (int k = 1; k <= n; ++k)
                u[k] = a[k];
            for (int k = 1; k <= i; ++k)
                u[b[k]] = 0;
            memset(c, false, sizeof c);
            z = 0;
            for (int k = 1; k <= i; ++k)
            {
                if (!c[b[k]])
                    dfs(b[k]);
            }
            if (qry(u) == 0)
                g[b[i]].push_back(b[j]);
            g[b[j]].pop_back();
        }
    }
    cout << "end" << endl;
    memset(c, false, sizeof c);
    for (int x = 1; x <= n; ++x)
    {
        if (!c[x])
            dfs1(x);
    }
    for (int x = 1; x <= n; ++x)
    {
        g[x].clear();
        for (set<int>::iterator it = s[x].begin(); it != s[x].end(); ++it)
            g[x].push_back(*it);
    }
    for (int x = 1; x <= n; ++x)
    {
        for (int i = 0; i < g[x].size(); ++i)
        {
            int h = g[x][i];
            gg[h].push_back(x);
        }
    }
    memset(c, false, sizeof c);
    z = 0;
    for (int x = 1; x <= n; ++x)
    {
        if (!c[x])
            dfs2(x);
    }
    memset(c, false, sizeof c);
    z = n + 1;
    for (int x = 1; x <= n; ++x)
    {
        if (!c[x])
            dfs3(x);
    }
    for (int i = 1; i <= n; ++i)
        cout << minu[i] << ' ';
    cout << endl;
    for (int i = 1; i <= n; ++i)
        cout << maxu[i] << ' ';
    cout << endl;
    return 0;
}

Compilation message

zagonetka.cpp: In function 'void dfs(int)':
zagonetka.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs1(int)':
zagonetka.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs2(int)':
zagonetka.cpp:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x].size(); ++i)
                     ~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs3(int)':
zagonetka.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < gg[x].size(); ++i)
                     ~~^~~~~~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:127:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < g[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 376 KB Output is correct
2 Correct 26 ms 324 KB Output is correct
3 Correct 33 ms 380 KB Output is correct
4 Correct 41 ms 248 KB Output is correct
5 Correct 14 ms 248 KB Output is correct
6 Correct 43 ms 376 KB Output is correct
7 Correct 9 ms 248 KB Output is correct
8 Correct 10 ms 248 KB Output is correct
9 Correct 38 ms 376 KB Output is correct
10 Correct 12 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 4 ms 248 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 8 ms 376 KB Output is correct
7 Correct 6 ms 248 KB Output is correct
8 Correct 8 ms 248 KB Output is correct
9 Correct 9 ms 376 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 8 ms 248 KB Output is correct
12 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 328 KB Output is correct
2 Correct 93 ms 248 KB Output is correct
3 Correct 77 ms 376 KB Output is correct
4 Correct 104 ms 460 KB Output is correct
5 Correct 141 ms 632 KB Output is correct
6 Correct 149 ms 504 KB Output is correct
7 Correct 80 ms 460 KB Output is correct
8 Correct 83 ms 504 KB Output is correct
9 Correct 116 ms 500 KB Output is correct
10 Correct 93 ms 248 KB Output is correct
11 Correct 86 ms 248 KB Output is correct
12 Correct 69 ms 416 KB Output is correct
13 Correct 99 ms 380 KB Output is correct
14 Correct 89 ms 248 KB Output is correct
15 Correct 75 ms 376 KB Output is correct
16 Correct 89 ms 328 KB Output is correct