#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
std::vector<int> SB1(int N)
{
std::vector<int> T(N);
vector<int> winns(N);
vector<vector<bool>> answs(N, vector<bool>(N, false));
for (int i = 0; i < N; i++)
for (int e = 0; e < i; e++)
{
bool b = Query(i, e);
winns[b ? i : e]++;
answs[i][e] = b;
answs[e][i] = !b;
}
vector<int> l, f;
for (int i = 0; i < N; i++)
{
if (winns[i] == 1)
f.push_back(i);
else if (winns[i] == N - 2)
l.push_back(i);
else
T[i] = winns[i];
}
if (answs[l[1]][l[0]])
swap(l[0], l[1]);
T[l[0]] = N - 2;
T[l[1]] = N - 1;
if (answs[f[1]][f[0]])
swap(f[0], f[1]);
T[f[0]] = 0;
T[f[1]] = 1;
return T;
}
std::vector<int> merge(vector<int> pt1, vector<int> pt2)
{
vector<int> arr;
int a = 0, b = 0;
while (a != pt1.size() || pt2.size() != b)
{
if (pt1.size() != a && (pt2.size() == b || !Query(pt1[a], pt2[b])))
{
arr.push_back(pt1[a++]);
}
else
{
arr.push_back(pt2[b++]);
}
}
return arr;
}
std::vector<int> mergeSort(vector<int> arr)
{
if (arr.size() <= 1)
return arr;
vector<int> pt1(arr.begin(), arr.begin() + arr.size() / 2);
vector<int> pt2(arr.begin() + arr.size() / 2, arr.end());
mergeSort(pt1);
mergeSort(pt2);
return merge(pt1, pt2);
}
std::vector<int> Solve(int N)
{
if ( N <= 200)
{
return SB1(N);
}
vector<int> monsters(N);
iota(monsters.begin(), monsters.end(), 0);
monsters = mergeSort(monsters);
/*for (int i = 0; i < N; i++)
{
cout << " " << S[monsters[i]];
}
cout << endl;*/
int unSorted = 0;
if (Query(monsters[0], monsters[1]))
{
unSorted++;
}
while (unSorted < N - 1)
{
int pivot = unSorted + 2;
while (pivot < N && Query(monsters[unSorted], monsters[pivot]))
{
pivot++;
}
reverse(monsters.begin() + unSorted, monsters.begin() + pivot);
unSorted=pivot;
}
/*for (int i = 0; i < N; i++)
{
cout << " " << S[monsters[i]];
}*/
return monsters;
}
Compilation message
monster.cpp: In function 'std::vector<int> merge(std::vector<int>, std::vector<int>)':
monster.cpp:49:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | while (a != pt1.size() || pt2.size() != b)
| ~~^~~~~~~~~~~~~
monster.cpp:49:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | while (a != pt1.size() || pt2.size() != b)
| ~~~~~~~~~~~^~~~
monster.cpp:51:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | if (pt1.size() != a && (pt2.size() == b || !Query(pt1[a], pt2[b])))
| ~~~~~~~~~~~^~~~
monster.cpp:51:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | if (pt1.size() != a && (pt2.size() == b || !Query(pt1[a], pt2[b])))
| ~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
188 ms |
200 KB |
Output is correct |
17 |
Correct |
186 ms |
200 KB |
Output is correct |
18 |
Correct |
196 ms |
200 KB |
Output is correct |
19 |
Correct |
133 ms |
200 KB |
Output is correct |
20 |
Correct |
205 ms |
200 KB |
Output is correct |
21 |
Correct |
0 ms |
200 KB |
Output is correct |
22 |
Correct |
0 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
224 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
0 ms |
200 KB |
Output is correct |
29 |
Correct |
1 ms |
200 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
105 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
188 ms |
200 KB |
Output is correct |
17 |
Correct |
186 ms |
200 KB |
Output is correct |
18 |
Correct |
196 ms |
200 KB |
Output is correct |
19 |
Correct |
133 ms |
200 KB |
Output is correct |
20 |
Correct |
205 ms |
200 KB |
Output is correct |
21 |
Correct |
0 ms |
200 KB |
Output is correct |
22 |
Correct |
0 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
224 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
0 ms |
200 KB |
Output is correct |
29 |
Correct |
1 ms |
200 KB |
Output is correct |
30 |
Correct |
1 ms |
200 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
105 ms |
200 KB |
Output is correct |
33 |
Incorrect |
70 ms |
304 KB |
Wrong Answer [3] |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
41 ms |
296 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |