#include "grader.h"
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(ll n)
{
ll q=(n>50?4000:n>7?7000:50)-1, cnt=-1;
vector <vector <ll>> p(n+1, vector <ll> (n+1, 1));
vector <ll> crr(n);
while (1)
{
cnt++;
if (cnt+1==q)
{
vector <ll> ans;
vector <bool> check(n, 0);
for (ll j=1; j<=n; j++)
for (ll k=1; k<=n; k++)
if (p[j][k] && !check[k]) {ans.pb(k), check[k]=1; break;}
query(ans); return;
}
if (cnt%n==0)
{
iota(crr.begin(), crr.end(), 1);
shuffle(crr.begin(), crr.end(), rng);
}
else rotate(crr.begin(), crr.begin()+1, crr.end());
ll cnt=0;
for (ll j=0; j<n; j++)
cnt+=p[j+1][crr[j]];
if (!cnt) continue;
ll q=query(crr);
if (q==n) return;
if (!q)
{
for (ll j=0; j<n; j++)
p[j+1][crr[j]]=0;
bool ok=1;
for (ll j=1; j<=n; j++)
{
ll cnt=0;
for (ll k=1; k<=n; k++)
cnt+=p[j][k];
if (cnt>1) ok=0;
}
if (ok)
{
vector <ll> ans;
for (ll j=1; j<=n; j++)
for (ll k=1; k<=n; k++)
if (p[j][k]) {ans.pb(k); break;}
query(ans); return;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Is not a permutation |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Is not a permutation |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Is not a permutation |
2 |
Halted |
0 ms |
0 KB |
- |