#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=1005;
int n, dp[nx][nx], cnt[nx], used[nx], pw[nx], x, y;
set<int> s[nx];
int query(int a, int b)
{
if (dp[a][b]) return dp[a][b]-1;
dp[a][b]=Query(a, b);
dp[b][a]=!dp[a][b];
dp[a][b]++, dp[b][a]++;
return dp[a][b]-1;
}
std::vector<int> Solve(int N) {
n=N;
for (int t=0; t<N; t++)
{
vector<int> v;
for (int i=0; i<N; i++) if (!used[i]&&s[i].empty()) v.push_back(i);
while (v.size()>1)
{
vector<int> tmp;
for (int i=0; i+1<v.size(); i+=2)
{
if (!query(v[i], v[i+1])) tmp.push_back(v[i]), s[v[i+1]].insert(v[i]);
else tmp.push_back(v[i+1]), s[v[i]].insert(v[i+1]);
}
if (v.size()%2) tmp.push_back(v.back());
v=tmp;
}
pw[t]=v[0];
used[v[0]]=1;
for (int i=0; i<N; i++) if (s[i].find(v[0])!=s[i].end()) s[i].erase(v[0]);
}
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if (i==j) continue;
if (i<j-9) cnt[pw[j]]++;
else if (i>j+9) cnt[pw[i]]++;
else
{
if (query(pw[i], pw[j])) cnt[pw[i]]++;
else cnt[pw[j]]++;
}
}
}
vector<pair<int ,int>> v;
for (int i=0; i<n; i++) v.push_back({cnt[i], i});
sort(v.begin(), v.end());
vector<int> res(n), ans(n);
for (int i=0; i<n; i++) res[i]=v[i].second;
if (!query(res[0], res[1])) swap(res[0], res[1]);
if (!query(res[n-2], res[n-1])) swap(res[n-2], res[n-1]);
for (int i=0; i<n; i++) ans[res[i]]=i;
return ans;
}
Compilation message
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i=0; i+1<v.size(); i+=2)
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
13 ms |
2676 KB |
Output is correct |
17 |
Correct |
18 ms |
2648 KB |
Output is correct |
18 |
Correct |
12 ms |
2668 KB |
Output is correct |
19 |
Correct |
10 ms |
2648 KB |
Output is correct |
20 |
Correct |
14 ms |
2908 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
2648 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
8 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
13 ms |
2676 KB |
Output is correct |
17 |
Correct |
18 ms |
2648 KB |
Output is correct |
18 |
Correct |
12 ms |
2668 KB |
Output is correct |
19 |
Correct |
10 ms |
2648 KB |
Output is correct |
20 |
Correct |
14 ms |
2908 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
2648 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
8 ms |
2648 KB |
Output is correct |
33 |
Correct |
94 ms |
4440 KB |
Output is correct |
34 |
Correct |
103 ms |
4440 KB |
Output is correct |
35 |
Correct |
102 ms |
4440 KB |
Output is correct |
36 |
Correct |
108 ms |
4440 KB |
Output is correct |
37 |
Correct |
109 ms |
4440 KB |
Output is correct |
38 |
Correct |
99 ms |
4440 KB |
Output is correct |
39 |
Correct |
117 ms |
4452 KB |
Output is correct |
40 |
Correct |
96 ms |
4440 KB |
Output is correct |
41 |
Correct |
81 ms |
4440 KB |
Output is correct |
42 |
Correct |
85 ms |
4692 KB |
Output is correct |
43 |
Correct |
48 ms |
4440 KB |
Output is correct |
44 |
Correct |
57 ms |
4696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
4440 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |