Submission #640985

# Submission time Handle Problem Language Result Execution time Memory
640985 2022-09-15T16:30:09 Z CDuong Zagonetka (COI18_zagonetka) C++17
0 / 100
1 ms 464 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
*/
#include <bits/stdc++.h>
#define taskname "bai3"
#define ll long long
#define all(x) x.begin(), x.end()
#define float long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define pii pair<int, int>
using namespace std;
const int mxN = 1e5 + 5;
const int mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;
int n, cnt, p[105], trc[105], idx[105], pos[105], pf[105], ans[105], trc1[105], ans1[105];
bool vis[105];
vector<int> top_sort, G[105], Gr[105], Gr1[105];
void dfs(int node, int x, int y){
    for(auto u : G[node]){
        if(!vis[u] && x <= u && u <= y){
            vis[u] = true;
            dfs(u, x, y);
        }
    }
    top_sort.pb(node);
}
int ask(int x, int y){
    memset(vis, 0, sizeof(vis));
    top_sort.clear();
    G[y].pb(x);
    for(int i = x; i <= y; ++i){
        if(!vis[i]){
            vis[i] = true;
            dfs(i, x, y);
        }
    }
    reverse(all(top_sort));
    for(int i = x; i <= y; ++i){
        idx[top_sort[i - x]] = i;
    }
    for(int i = x; i <= y; ++i){
        for(int j : G[i]){
            if(x <= j && j <= y && idx[j] <= idx[i]){
                G[y].pop_back();
                return -1;
            }
        }
    }
    G[y].pop_back();
    vector<int> idxx;
    for(int i = 1; i < x; ++i) idxx.pb(i);
    for(int i = x; i <= y; ++i){
        idxx.pb(top_sort[i - x]);
    }
    for(int i = y + 1; i <= n; ++i) idxx.pb(i);
    for(int i = 0; i < n; ++i){
        pf[pos[idxx[i]]] = i + 1;
    }
    cout << "query ";
    for(int i = 1; i <= n; ++i){
        cout << pf[i] << " ";
    }
    cout << endl; //cout.flush();
    int tmp; cin >> tmp;
    if(tmp == 0){
        G[x].pb(y);
        Gr[pos[x]].pb(pos[y]);
        trc[pos[y]]++;
    }
}
void solve(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> p[i];
        pos[p[i]] = i;
    }
    for(int range = 1; range < n; ++range){
        for(int i = 1; i <= n - range; ++i){
            int tmp = ask(i, i + range);
        }
    }
    cout << "end\n";

    priority_queue<int> pq;

    for(int i = 1; i <= n; ++i){
        // << trc[i] << " ";
        if(trc[i] == 0){
            pq.push(i);
        }
    }
    //cout << endl;

    while(!pq.empty()){
        int tmp = pq.top();
        pq.pop();
        ans[tmp] = ++cnt;
        for(int v : Gr[tmp]){
            trc[v]--;
            if(trc[v] == 0) pq.push(v);
        }
    }


    for(int i = 1; i <= n; ++i){
        for(int v : Gr[i]){
            Gr1[v].pb(i);
            trc1[i]++;
        }
    }

    for(int i = 1; i <= n; ++i){
        if(trc1[i] == 0){
            pq.push(i);
        }
    }
    while(!pq.empty()){
        int tmp = pq.top();
        pq.pop();
        ans1[tmp] = cnt--;
        for(int v : Gr1[tmp]){
            trc1[v]--;
            if(trc1[v] == 0) pq.push(v);
        }
    }
    for(int i = 1; i <= n; ++i){
        cout << ans1[i] << " ";
    }
    cout << endl;
    for(int i = 1; i <= n; ++i){
        cout << ans[i] << " ";
    }
    cout << endl;
}
signed main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    //freopen(taskname".inp", "r", stdin);
    //freopen(taskname".out", "w", stdout);
    int t = 1; //cin >> t;
    while(t--) solve();
}

Compilation message

zagonetka.cpp: In function 'void solve()':
zagonetka.cpp:85:17: warning: unused variable 'tmp' [-Wunused-variable]
   85 |             int tmp = ask(i, i + range);
      |                 ^~~
zagonetka.cpp: In function 'int ask(int, int)':
zagonetka.cpp:56:17: warning: control reaches end of non-void function [-Wreturn-type]
   56 |     vector<int> idxx;
      |                 ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -