Submission #640620

# Submission time Handle Problem Language Result Execution time Memory
640620 2022-09-15T03:32:28 Z socpite Zagonetka (COI18_zagonetka) C++17
0 / 100
4 ms 1472 KB
#include<bits/stdc++.h>
using namespace std;
 
#define f first 
#define s second 
 
typedef long long ll;
typedef long double ld;

const int maxn = 105;
const int mod = 1e9+7;

int n;

vector<int> g[maxn], fg[maxn];

int vis[maxn], pos[maxn], qry[maxn], p[maxn], deg[maxn], cnt[maxn], ans[maxn];                                                                                                                                                                                                                                  ;

vector<int> vec;
set<int> st;

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

void dfs(int x, int l, int r){
    vec.push_back(x);
    vis[x]=1;
    for(auto v: g[x]){
        if(v > r || v < l)continue;
        if(!vis[v])dfs(v, l, r);
    }
}

void fe(int l, int r){
    for(int i = 1; i <= n; i++)vis[i]=0;
    dfs(r, l, r);
    if(vis[l])return;
    vector<int> sus;
    sort(vec.begin(), vec.end());
    sus.insert(sus.end(), vec.begin(), vec.end());
    vec.clear();
    dfs(l, l, r);
    sort(vec.begin(), vec.end());
    sus.insert(sus.end(), vec.begin(), vec.end());
    vector<int> notsus = sus;
    sort(notsus.begin(), notsus.end());
    vec.clear();
    for(int i = 1; i <= n; i++)qry[i]=p[i];
    for(int i = 0; i < sus.size(); i++){
        qry[pos[sus[i]]]=notsus[i];
    }
    if(ask()){
        g[l].push_back(r);
        g[r].push_back(l);
        fg[pos[r]].push_back(pos[l]);
        deg[pos[l]]++;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
        pos[p[i]]=i;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j+i <= n; j++){
            fe(j, i+j);
        }
    }
    cout << "end" << endl;
    for(int i = 1; i <= n; i++)if(!deg[i])st.insert(i);
    for(int i = n; i > 0; i--){
        auto x = *prev(st.end());
        st.erase(x);
        ans[x]=i;
        for(auto v: fg[x]){
            cnt[v]++;
            if(cnt[v] == deg[v])st.insert(v);
        }
    }
    for(int i = 1; i <= n; i++)cout << ans[i] << " ";
    cout << endl;
    for(int i = 1; i <= n; i++){
        if(!deg[i])st.insert(i);
        cnt[i]=0;
    }
    for(int i = n; i > 0; i--){
        auto x = *st.begin();
        st.erase(x);
        ans[x]=i;
        for(auto v: fg[x]){
            cnt[v]++;
            if(cnt[v] == deg[v])st.insert(v);
        }
    }
    for(int i = 1; i <= n; i++)cout << ans[i] << " ";
    cout << endl;
}

/*
1 3 5 4 2
*/

Compilation message

zagonetka.cpp: In function 'void fe(int, int)':
zagonetka.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0; i < sus.size(); i++){
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1472 KB Output isn't correct
2 Halted 0 ms 0 KB -