# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552113 | Killer2501 | Zagonetka (COI18_zagonetka) | C++14 | 88 ms | 496 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<int, pii>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e2+5;
const int M = 17;
const int mod = 1e9+7;
const ll base = 75;
const ll inf = 1e16;
int n, m, k, q, a[N], dd[N][N], b[N], d[N], c[N], dp[2][N];
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
b[a[i]] = i;
}
for(int i = n-1; i; i --)
{
fill_n(d, n+1, 0);
d[i] = 1;
for(int j = i+1; j <= n; j ++)
{
int cnt = 0;
for(int p = 1; p <= j; p ++)if(!d[p])c[b[p]] = ++cnt;
for(int p = i; p <= n; p ++)if(d[p] || p > j)c[b[p]] = ++cnt;
cout << "query ";
for(int p = 1; p <= n; p ++)cout << c[p] <<" ";
cout << endl;
cin >> k;
if(!k)
{
for(int p = 1; p <= n; p ++)
{
if(dd[j][p] || p == j)
{
dd[i][p] = 1;
d[p] = 1;
}
}
}
}
}
for(int i = 1; i <= n; i ++)
{
dp[0][i] = i;
dp[1][i] = n-i+1;
for(int j = 1; j <= n; j ++)
{
if(b[j] < i && dd[j][a[i]])dp[1][i] = max(dp[1][i], dp[1][b[j]]);
if(b[j] < i && dd[a[i]][j])dp[0][i] = min(dp[0][i], dp[0][b[j]]);
}
for(int j = 1; j < i; j ++)
{
dp[0][j] += (dp[0][j] >= dp[0][i]);
dp[1][j] -= (dp[1][j] <= dp[1][i]);
}
}
cout << "end" << endl;
for(int i = 0; i < 2; i ++)
{
for(int j = 1; j <= n; j ++)cout << dp[i][j] <<" ";
cout << endl;
}
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "tests"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |