답안 #249255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
249255 2020-07-14T14:18:08 Z Vimmer Zagonetka (COI18_zagonetka) C++14
100 / 100
93 ms 2556 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100010
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 6> a6;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

map <vector <int>, bool> mp;

bool checker(vector <int> &g)
{
    if (mp.find(g) != mp.end()) return mp[g];

    cout << "query ";

    for (auto it : g) cout << it << " ";

    cout << endl;

    bool ans;

    cin >> ans;

    mp[g] = ans;

    return ans;
}


vector <int> ans;

int p[150], pos[150], cur = 1, n;

bool gd[150][150], bn[150][150], mk[150];

void dfs(int v)
{
    if (mk[v]) return;

    mk[v] = 1;

    for (int i = 0; i < n; i++)
    {
        if (i == v) continue;

        if (bn[i][v]) dfs(i);
    }

    ans[v] = cur++;
}

void rec(int v)
{
    if (mk[v]) return;

    mk[v] = 1;

    for (int i = 0; i < n; i++)
    {
        if (i == v) continue;

        if (bn[v][i]) rec(i);
    }

    ans[v] = cur--;
}
int main()
{
    //freopen("input.txt", "r", stdin); freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;

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

        pos[p[i]] = i;

        gd[p[i]][p[i]] = 1;
    }

    for (int len = 1; len <= n; len++)
      for (int i = 1; i <= n; i++)
      {
            int nxt = i + len;

            if (nxt > n) continue;

            bool fnd = 0;

            for (int md = i + 1; md < nxt; md++)
              if (gd[i][md] && gd[md][nxt]) {fnd = 1; break;}

            if (fnd)
            {
                gd[i][nxt] = 1;

                continue;
            }

            vector <int> v, gr; v.clear(); gr.resize(n);

            for (int j = 0; j < n; j++) gr[j] = p[j];

            for (int md = i; md <= nxt; md++)
                if (gd[i][md] || gd[md][nxt]) v.pb(md);

            reverse(v.begin(), v.end());

            int j = 0;

            for (int md = nxt; md >= i; md--)
                if (gd[i][md]) gr[pos[md]] = v[j++];

            for (int md = nxt; md >= i; md--)
                if (gd[md][nxt]) gr[pos[md]] = v[j++];

            gd[i][nxt] = !checker(gr);
      }

    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
          bn[pos[i]][pos[j]] = gd[i][j];

    ans.resize(n);

    for (int i = 0; i < n; i++)
        dfs(i);

    cout << "end" << endl;

    for (auto it : ans) cout << it << " "; cout << endl;

    cur = n;

    memset(mk, 0, sizeof(mk));

    ans.resize(n);

    for (int i = 0; i < n; i++)
        rec(i);

    for (auto it : ans) cout << it << " "; cout << endl;
}

Compilation message

zagonetka.cpp: In function 'int main()':
zagonetka.cpp:156:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (auto it : ans) cout << it << " "; cout << endl;
     ^~~
zagonetka.cpp:156:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (auto it : ans) cout << it << " "; cout << endl;
                                            ^~~~
zagonetka.cpp:167:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (auto it : ans) cout << it << " "; cout << endl;
     ^~~
zagonetka.cpp:167:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     for (auto it : ans) cout << it << " "; cout << endl;
                                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 400 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 632 KB Output is correct
2 Correct 29 ms 908 KB Output is correct
3 Correct 27 ms 1056 KB Output is correct
4 Correct 33 ms 1172 KB Output is correct
5 Correct 10 ms 512 KB Output is correct
6 Correct 40 ms 1144 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 5 ms 404 KB Output is correct
9 Correct 32 ms 1144 KB Output is correct
10 Correct 20 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 2296 KB Output is correct
2 Correct 92 ms 2556 KB Output is correct
3 Correct 84 ms 2168 KB Output is correct
4 Correct 2 ms 412 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 17 ms 760 KB Output is correct
8 Correct 30 ms 1144 KB Output is correct
9 Correct 23 ms 888 KB Output is correct
10 Correct 93 ms 2552 KB Output is correct
11 Correct 59 ms 2300 KB Output is correct
12 Correct 80 ms 2168 KB Output is correct
13 Correct 83 ms 2360 KB Output is correct
14 Correct 88 ms 2168 KB Output is correct
15 Correct 84 ms 2444 KB Output is correct
16 Correct 79 ms 2352 KB Output is correct