Submission #552113

#TimeUsernameProblemLanguageResultExecution timeMemory
552113Killer2501Zagonetka (COI18_zagonetka)C++14
100 / 100
88 ms496 KiB
#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)

zagonetka.cpp: In function 'int main()':
zagonetka.cpp:81:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
zagonetka.cpp:82:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...