/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define pb push_back
#define fi first
#define se second
#define eb emplace_back
#define ii pair<int, int>
#define vi vector<int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define ld long double
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 300005;
const ll oo = 1e18 + 7;
int n, a[maxN];
int x, y, z, k;
int posy[101];
bool aw[101][101];
int ray[101];
int cnt[101];
vector<int> vc[101];
void solve(){
priority_queue<int> pq;
for1(i, 1, n){
ray[i] = i;
vc[i].clear();
cnt[i] = 0;
}
//
for1(i, 1, n) for1(j, 1, n) if(aw[i][j]){
vc[posy[j]].pb(posy[i]);
++cnt[posy[i]];
}
x = n;
for1(i, 1, n) if(!cnt[i]) pq.push(i);
while(!pq.empty()){
int node = pq.top(); pq.pop();
a[node] = x--;
for(int cc : vc[node]){
--cnt[cc]; if(!cnt[cc]) pq.push(cc);
}
}
for1(i, 1, n) cout << a[i] << " ";
cout << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for1(i, 1, n){
cin >> x; posy[x] = i;
}
for1(len, 1, n) for1(l, 1, n){
int r = l + len; if(r > n) continue;
for1(i, 1, n){
ray[i] = i;
vc[i].clear();
cnt[i] = 0;
}
for1(i, l, r) ray[i] = 0;
int sta = r + 1;
for1(i, l, r) for1(j, i + 1, r) if(aw[i][j]){
vc[j].pb(i); ++cnt[i];
}
vc[l].pb(r); ++cnt[r];
vector<int> stk;
for1(i, l, r) if(!cnt[i]) stk.pb(i);
while(!stk.empty()){
int node = stk.back(); stk.pop_back();
ray[node] = --sta;
for(int cc : vc[node]){
--cnt[cc]; if(!cnt[cc]) stk.pb(cc);
}
}
x = 0;
for1(i, 1, n) if(!ray[i]) x = 1;
if(x){
aw[l][r] = 1; continue;
}
for1(i, 1, n) a[posy[i]] = ray[i];
cout << "query ";
for1(i, 1, n) cout << a[i] << " ";
cout << endl;
cin >> x; if(!x) aw[l][r] = 1;
}
cout << "end\n";
solve();
for1(i, 1, n) for1(j, i + 1, n) if(aw[i][j]){
aw[j][i] = 1; aw[i][j] = 0;
}
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |