#include <bits/stdc++.h>
using namespace std;
const int N = 102;
int n;
bool qry(int a[])
{
cout << "query";
for (int k = 1; k <= n; ++k)
cout << ' ' << a[k];
cout << endl;
int x;
cin >> x;
return x;
}
int a[N];
int b[N];
vector<int> g[N];
int z;
bool c[N];
int u[N];
void dfs(int x)
{
c[x] = true;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (!c[h])
dfs(h);
}
u[x] = ++z;
}
void dfs1(int x)
{
c[x] = true;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (!c[h])
dfs1(h);
for (int j = 0; j < g[h].size(); ++j)
g[x].push_back(g[h][j]);
}
}
int minu[N];
void dfs2(int x)
{
c[x] = true;
sort(g[x].begin(), g[x].end());
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (!c[h])
dfs2(h);
}
minu[x] = ++z;
}
vector<int> gg[N];
int maxu[N];
void dfs3(int x)
{
c[x] = true;
sort(gg[x].begin(), gg[x].end());
for (int i = 0; i < gg[x].size(); ++i)
{
int h = gg[x][i];
if (!c[h])
dfs3(h);
}
maxu[x] = --z;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
{
b[a[i]] = i;
}
for (int i = 2; i <= n; ++i)
{
for (int j = i - 1; j >= 1; --j)
{
g[b[j]].push_back(b[i]);
for (int k = 1; k <= n; ++k)
u[k] = a[k];
for (int k = 1; k <= i; ++k)
u[b[k]] = 0;
memset(c, false, sizeof c);
z = 0;
for (int k = 1; k <= i; ++k)
{
if (!c[b[k]])
dfs(b[k]);
}
if (qry(u))
g[b[i]].push_back(b[j]);
g[b[j]].pop_back();
}
}
cout << "end" << endl;
memset(c, false, sizeof c);
for (int x = 1; x <= n; ++x)
{
dfs1(x);
}
for (int x = 1; x <= n; ++x)
{
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
gg[h].push_back(x);
}
}
memset(c, false, sizeof c);
z = 0;
for (int x = 1; x <= n; ++x)
{
if (!c[x])
dfs2(x);
}
memset(c, false, sizeof c);
z = n + 1;
for (int x = n; x >= 1; --x)
{
if (!c[x])
dfs3(x);
}
for (int i = 1; i <= n; ++i)
cout << minu[i] << ' ';
cout << endl;
for (int i = 1; i <= n; ++i)
cout << maxu[i] << ' ';
cout << endl;
return 0;
}
Compilation message
zagonetka.cpp: In function 'void dfs(int)':
zagonetka.cpp:29:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs1(int)':
zagonetka.cpp:41:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
zagonetka.cpp:46:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < g[h].size(); ++j)
~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs2(int)':
zagonetka.cpp:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
zagonetka.cpp: In function 'void dfs3(int)':
zagonetka.cpp:71:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < gg[x].size(); ++i)
~~^~~~~~~~~~~~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:118:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[x].size(); ++i)
~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
248 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2718 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1668 ms |
181100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2754 ms |
1048576 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |