#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
bool check = false,adj[N + 1][N + 1],temp[N + 1][N + 1],vis[N + 1];
int deg[N + 1],num[N + 1],pos[N + 1],n;
vector<int> topo;
void init(int l,int r) {
for(int i = 1;i <= n;i++) {
deg[i] = 0;
vis[i] = false;
}
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) temp[i][j] = false;
}
for(int i = l;i <= r;i++) {
for(int j = l;j <= r;j++) {
temp[pos[i]][pos[j]] = adj[pos[i]][pos[j]];
if(adj[pos[i]][pos[j]]) {
deg[pos[j]]++;
}
}
}
check = true;
}
void dfs(int s) {
if(vis[s]) {
check = false;
return;
}
topo.push_back(s);
vis[s] = true;
for(int i = 1;i <= n;i++) {
if(temp[s][i]) {
dfs(i);
}
}
}
int res[N + 1];
int query() {
for(int i = 0;i < topo.size();i++) {
res[topo[i]] = i + 1;
}
cout<<"query ";
for(int i = 1;i <= n;i++) cout<<res[i]<<" ";
cout<<endl;
int x;
cin>>x;
return x;
}
void small() {
priority_queue<int> q;
vector<int> kq;
for(int i = 1;i <= n;i++) {
if(deg[i] == 0) q.push(i);
}
while(!q.empty()) {
int s = q.top();
q.pop();
kq.push_back(s);
for(int i = 1;i <= n;i++) {
if(adj[s][i]) {
q.push(i);
}
}
}
reverse(kq.begin(),kq.end());
for(int i = 0;i < kq.size();i++) {
res[kq[i]] = i + 1;
}
for(int i = 1;i <= n;i++) cout<<res[i]<<" ";
cout<<endl;
}
void big() {
priority_queue<int> q;
vector<int> kq;
for(int i = 1;i <= n;i++) {
if(deg[i] == 0) q.push(-i);
}
while(!q.empty()) {
int s = -q.top();
kq.push_back(s);
q.pop();
for(int i = 1;i <= n;i++) {
if(adj[s][i]) {
q.push(-i);
}
}
}
reverse(kq.begin(),kq.end());
for(int i = 0;i < kq.size();i++) {
res[kq[i]] =i + 1;
}
for(int i= 1;i <= n;i++) cout<<res[i]<<" ";
cout<<endl;
}
int main() {
cin>>n;
for(int i = 1;i <= n;i++) {
cin>>num[i];
pos[num[i]] = i;
}
for(int len = 1;len <= n - 1;len++) {
for(int p = 1;p + len <= n;p++) {
adj[pos[p + len]][pos[p]] = true;
init(p,p + len);
topo.clear();
for(int i = 1;i < p;i++) {
topo.push_back(pos[i]);
}
for(int i = p;i <= p + len;i++) {
if(deg[pos[i]] == 0) {
dfs(pos[i]);
}
}
for(int i = p + len + 1;i <= n;i++) {
topo.push_back(pos[i]);
}
adj[pos[p + len]][pos[p]] = false;
if(!check || !query()) {
adj[pos[p]][pos[p + len]] = true;
}
}
}
for(int i = 1;i <= n;i++) {
for(int j = i + 1;j <= n;j++) {
if(adj[i][j]) {
adj[j][i] = true;
adj[i][j] = false;
} else if(adj[j][i]) {
adj[i][j] = true;
adj[j][i] = false;
}
}
}
init(1,n);
cout<<"end"<<endl;
small();
big();
exit(0);
return 0;
}
Compilation message
zagonetka.cpp: In function 'int query()':
zagonetka.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0;i < topo.size();i++) {
| ~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void small()':
zagonetka.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 0;i < kq.size();i++) {
| ~~^~~~~~~~~~~
zagonetka.cpp: In function 'void big()':
zagonetka.cpp:102:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int i = 0;i < kq.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 |
13 ms |
208 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Runtime error |
1 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
114 ms |
300 KB |
Integer 94 violates the range [1, 93] |
2 |
Halted |
0 ms |
0 KB |
- |