#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using pii = pair<pair<ll, ll>, ll>;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
int n;
int pos[105];
int a[105];
int ray[105];
int ok[105][105];
int den[105];
int mang[105];
vector<int> G[105];
void print()
{
for (int i = 1; i <= n; i++)
{
ray[i] = i;
den[i] = 0;
G[i].clear();
}
priority_queue<int> pq;
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (ok[i][j])
{
G[pos[j]].push_back(pos[i]);
den[pos[i]]++;
}
}
}
for (int i = 1; i <= n; i++)
{
if (den[i] == 0)
{
pq.push(i);
}
}
int luot = n + 1;
while (pq.size())
{
int z = pq.top();
pq.pop();
mang[z] = --luot;
for (auto v : G[z])
{
den[v]--;
if (!den[v])
pq.push(v);
}
}
for (int i = 1; i <= n; i++)
{
cout << mang[i] << ' ';
}
cout << endl;
}
void print2()
{
for (int i = 1; i <= n; i++)
{
ray[i] = i;
den[i] = 0;
G[i].clear();
}
priority_queue<int> pq;
for (int i = 1; i <= n; i++)
{
for (int j = i + 1; j <= n; j++)
{
if (ok[i][j])
{
G[pos[i]].push_back(pos[j]);
den[pos[j]]++;
}
}
}
for (int i = 1; i <= n; i++)
{
if (den[i] == 0)
{
pq.push(i);
}
}
int luot = 0;
while (pq.size())
{
int z = pq.top();
pq.pop();
mang[z] = ++luot;
for (auto v : G[z])
{
den[v]--;
if (!den[v])
pq.push(v);
}
}
for (int i = 1; i <= n; i++)
{
cout << mang[i] << ' ';
}
}
signed main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
pos[a[i]] = i;
}
for (int len = 1; len <= n; len++)
{
for (int l = 1; l <= n - len; l++)
{
int r = l + len;
for (int i = 1; i <= n; i++)
{
ray[i] = i;
den[i] = 0;
G[i].clear();
}
for (int i = l; i <= r; i++)
{
ray[i] = 0;
}
for (int i = l; i <= r; i++)
{
for (int j = i + 1; j <= r; j++)
{
if (ok[i][j])
{
G[j].push_back(i);
den[i]++;
}
}
}
G[l].push_back(r);
den[r]++;
queue<int> topo;
int luot = r + 1;
for (int i = l; i <= r; i++)
{
if (!den[i])topo.push(i);
}
while (topo.size())
{
int z = topo.front();
topo.pop();
ray[z] = --luot;
for (auto v : G[z])
{
den[v]--;
if (!den[v])
topo.push(v);
}
}
int check = 0;
for (int i = 1; i <= n; i++)
{
if (!ray[i])
check = 1;
}
if (check == 1)
{
ok[l][r] = 1;
continue;
}
for (int i = 1; i <= n; i++)
{
mang[pos[i]] = ray[i];
}
cout << "query ";
for (int i = 1; i <= n; i++)
{
cout << mang[i] << ' ';
}
cout << endl;
int x;
cin >> x;
if (!x)
ok[l][r] = 1;
}
}
cout << "end " << endl;
print();
print2();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
312 KB |
Output is correct |
2 |
Correct |
28 ms |
208 KB |
Output is correct |
3 |
Correct |
34 ms |
304 KB |
Output is correct |
4 |
Correct |
44 ms |
300 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Correct |
37 ms |
208 KB |
Output is correct |
7 |
Correct |
5 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
304 KB |
Output is correct |
9 |
Correct |
33 ms |
304 KB |
Output is correct |
10 |
Correct |
18 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
3 ms |
312 KB |
Output is correct |
4 |
Correct |
4 ms |
320 KB |
Output is correct |
5 |
Correct |
3 ms |
316 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
308 KB |
Output is correct |
9 |
Correct |
5 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
5 ms |
208 KB |
Output is correct |
12 |
Correct |
5 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
308 KB |
Output is correct |
2 |
Correct |
97 ms |
316 KB |
Output is correct |
3 |
Correct |
78 ms |
300 KB |
Output is correct |
4 |
Correct |
21 ms |
360 KB |
Output is correct |
5 |
Correct |
25 ms |
340 KB |
Output is correct |
6 |
Correct |
30 ms |
380 KB |
Output is correct |
7 |
Correct |
33 ms |
472 KB |
Output is correct |
8 |
Correct |
52 ms |
320 KB |
Output is correct |
9 |
Correct |
46 ms |
340 KB |
Output is correct |
10 |
Correct |
125 ms |
316 KB |
Output is correct |
11 |
Correct |
73 ms |
340 KB |
Output is correct |
12 |
Correct |
74 ms |
300 KB |
Output is correct |
13 |
Correct |
63 ms |
320 KB |
Output is correct |
14 |
Correct |
77 ms |
316 KB |
Output is correct |
15 |
Correct |
89 ms |
328 KB |
Output is correct |
16 |
Correct |
97 ms |
328 KB |
Output is correct |