#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100010
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 6> a6;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
bool checker(vector <int> &g)
{
cout << "query ";
for (auto it : g) cout << it << " ";
cout << endl;
bool ans;
cin >> ans;
return ans;
}
vector <int> ans;
int p[150], pos[150], cur = 1, n;
bool gd[150][150], bn[150][150], mk[150];
void dfs(int v)
{
if (mk[v]) return;
mk[v] = 1;
for (int i = 1; i <= n; i++)
{
if (i == v + 1) continue;
if (bn[i][v + 1]) dfs(i - 1);
}
ans[v] = cur++;
}
void rec(int v)
{
if (mk[v]) return;
mk[v] = 1;
for (int i = 1; i <= n; i++)
{
if (i == v + 1) continue;
if (bn[v + 1][i]) rec(v - 1);
}
ans[v] = cur--;
}
int main()
{
//freopen("input.txt", "r", stdin); freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> p[i];
pos[p[i]] = i;
gd[i][i] = 1;
}
for (int len = 1; len <= n; len++)
for (int i = 1; i <= n; i++)
{
int nxt = i + len;
if (nxt > n) continue;
bool fnd = 0;
for (int md = i; md <= nxt; md++)
if (gd[i][md] && gd[md][nxt]) {fnd = 1; break;}
if (fnd)
{
gd[i][nxt] = 1;
continue;
}
vector <int> v, gr; v.clear(); gr.resize(n);
for (int i = 0; i < n; i++) gr[i] = p[i];
for (int md = i; md <= nxt; md++)
if (gd[i][md] || gd[md][nxt]) v.pb(md);
reverse(v.begin(), v.end());
int j = 0;
for (int md = nxt; md >= i; md--)
if (gd[i][md]) gr[pos[md]] = v[j++];
for (int md = nxt; md >= i; md--)
if (gd[md][nxt]) gr[pos[md]] = v[j++];
gd[i][nxt] = !checker(gr);
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
bn[pos[i]][pos[j]] = gd[i][j];
ans.resize(n);
for (int i = 0; i < n; i++) dfs(i);
cout << "end" << endl;
for (auto it : ans) cout << it << " "; cout << endl;
cur = n;
memset(mk, 0, sizeof(mk));
ans.resize(n);
for (int i = n; i >= 1; i--) rec(i);
for (auto it : ans) cout << it << " "; cout << endl;
}
Compilation message
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:149:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : ans) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:149:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : ans) cout << it << " "; cout << endl;
^~~~
zagonetka.cpp:159:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : ans) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:159:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : ans) cout << it << " "; cout << endl;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |