#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
/*vector<int> a;
int querycount=0;
bool Query(int x, int y)
{
//cout << "? " << x << " " << y << '\n';
bool win=false;
if (a[x]-a[y]>1 || a[y]-a[x]==1)
win=true;
querycount=querycount+1;
//cout << win << '\n';
return win;
}*/
bool compare(int x, int y)
{
return !Query(x, y);
}
int firstelement(int x, int n)
{
int win=0;
for (int i=0; i<n; i++)
{
if (i==x)
continue;
win=win+Query(x, i);
}
if (win<2)
return 0;
return 1;
}
int bigfirstelement(int x, int n)
{
int win=0;
for (int i=0; i<n; i++)
{
if (i==x)
continue;
win=win+Query(x, i);
}
if (win==n-2)
return n-1;
return n-2;
}
vector<int> Solve(int n)
{
int order[n];
for (int i=0; i<n; i++)
order[i]=i;
sort(order, order+n, compare);
vector<int> win;
for (int i=1; i<n; i++)
if (Query(order[0], order[i]))
win.push_back(i);
int current;
if (win.size()<2)
current=firstelement(order[win[0]], n);
else if (win.size()==n-2)
current=bigfirstelement(order[1], n);
else
current=win[win.size()-2];
vector<int> strength;
int last=-1, check=0, x=current;
while (x>last)
{
strength.push_back(x);
x=x-1;
}
while (strength.size()<n)
{
for (int i=strength.size(); i<n; i++)
if (Query(order[check], order[i]))
{
check=strength.size();
last=current;
current=current+(i-strength.size()+1);
break;
}
x=current;
while (x>last)
{
strength.push_back(x);
x=x-1;
}
}
vector<int> finalstrength(n);
for (int i=0; i<n; i++)
finalstrength[order[i]]=strength[i];
return finalstrength;
}
/*int main()
{
a={0, 1, 2, 3};
for (auto x : a)
cout << x << " ";
cout << '\n';
ifstream fin("C:/Users/sofij/OneDrive/Desktop/cross.txt");
int n;
fin >> n;
for (int i=0; i<n; i++)
{
int ai;
fin >> ai;
a.push_back(ai);
}
vector<int> t=Solve(n);
for (auto x : t)
cout << x << " ";
cout << '\n';
cout << "query count " << querycount << '\n';
return 0;
}*/
/*#include <bits/stdc++.h>
#include "monster.h"
using namespace std;
vector<int> a;
bool Query(int x, int y)
{
cout << "? " << x << " " << y << '\n';
bool win=false;
if (a[x]-a[y]>1 || a[y]-a[x]==1)
win=true;
cout << win << '\n';
return win;
}
vector<int> Solve(int n)
{
int wins[n]={0};
bool outcome[n][n];
vector<int> strength(n);
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
{
outcome[i][j]=Query(i, j);
if (outcome[i][j]==true)
wins[i]=wins[i]+1;
else
wins[j]=wins[j]+1;
}
cout << "wins\n";
for (int i=0; i<n; i++)
cout << wins[i] << " ";
cout << '\n';
for (int i=0; i<n; i++)
strength[i]=wins[i];
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
{
if (wins[i]==n-2 && wins[j]==n-2)
{
strength[i]=n-1;
strength[j]=n-2;
if (outcome[i][j]==true)
swap(strength[i], strength[j]);
}
if (wins[i]==1 && wins[j]==1)
{
strength[i]=1;
strength[j]=0;
if (outcome[i][j]==true)
swap(strength[i], strength[j]);
}
}
return strength;
}
int main()
{
a={3, 1, 4, 2, 0};
vector<int> t=Solve(5);
for (auto x : t)
cout << x << " ";
return 0;
}*/
Compilation message
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:68:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
68 | else if (win.size()==n-2)
| ~~~~~~~~~~^~~~~
monster.cpp:79:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
79 | while (strength.size()<n)
| ~~~~~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
9 ms |
436 KB |
Output is correct |
17 |
Correct |
8 ms |
600 KB |
Output is correct |
18 |
Correct |
9 ms |
436 KB |
Output is correct |
19 |
Correct |
7 ms |
600 KB |
Output is correct |
20 |
Correct |
9 ms |
436 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 |
0 ms |
380 KB |
Output is correct |
26 |
Correct |
9 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
416 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
6 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
0 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 |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
9 ms |
436 KB |
Output is correct |
17 |
Correct |
8 ms |
600 KB |
Output is correct |
18 |
Correct |
9 ms |
436 KB |
Output is correct |
19 |
Correct |
7 ms |
600 KB |
Output is correct |
20 |
Correct |
9 ms |
436 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 |
0 ms |
380 KB |
Output is correct |
26 |
Correct |
9 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
416 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
6 ms |
600 KB |
Output is correct |
33 |
Correct |
59 ms |
852 KB |
Output is correct |
34 |
Correct |
56 ms |
676 KB |
Output is correct |
35 |
Correct |
66 ms |
412 KB |
Output is correct |
36 |
Correct |
70 ms |
416 KB |
Output is correct |
37 |
Correct |
63 ms |
424 KB |
Output is correct |
38 |
Correct |
59 ms |
412 KB |
Output is correct |
39 |
Correct |
61 ms |
600 KB |
Output is correct |
40 |
Correct |
58 ms |
412 KB |
Output is correct |
41 |
Correct |
55 ms |
412 KB |
Output is correct |
42 |
Correct |
66 ms |
672 KB |
Output is correct |
43 |
Correct |
49 ms |
668 KB |
Output is correct |
44 |
Correct |
52 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
62 ms |
416 KB |
Partially correct |
2 |
Partially correct |
56 ms |
416 KB |
Partially correct |
3 |
Partially correct |
67 ms |
592 KB |
Partially correct |
4 |
Partially correct |
69 ms |
592 KB |
Partially correct |
5 |
Partially correct |
53 ms |
412 KB |
Partially correct |
6 |
Partially correct |
55 ms |
668 KB |
Partially correct |
7 |
Partially correct |
64 ms |
432 KB |
Partially correct |
8 |
Partially correct |
57 ms |
424 KB |
Partially correct |
9 |
Partially correct |
58 ms |
416 KB |
Partially correct |
10 |
Partially correct |
60 ms |
412 KB |
Partially correct |
11 |
Partially correct |
54 ms |
668 KB |
Partially correct |
12 |
Partially correct |
81 ms |
416 KB |
Partially correct |
13 |
Incorrect |
82 ms |
592 KB |
Wrong Answer [6] |
14 |
Halted |
0 ms |
0 KB |
- |