#include<bits/stdc++.h>
#include "monster.h"
using namespace std;
const int MAX_VAL=1000+5;
int nbVal,nbReq;
int memo[MAX_VAL][MAX_VAL];
int quest(int a,int b) {
if (a>b) {
return 1-quest(b,a);
}
if (memo[a][b]!=-1) {
return memo[a][b];
}
if (Query(a,b)) {
memo[a][b]=1;
}
else {
memo[a][b]=0;
}
nbReq++;
return memo[a][b];
}
vector<int> calc(vector<int> pers) {
int taille=pers.size();
if (taille==1) {
return pers;
}
int mid=taille/2;
vector<int> gau,dro,ans;
for (int i=0;i<mid;i++) {
gau.push_back(pers[i]);
}
for (int i=mid;i<taille;i++) {
dro.push_back(pers[i]);
}
gau=calc(gau);
dro=calc(dro);
while (!gau.empty() or !dro.empty()) {
if (gau.empty()) {
ans.push_back(dro.back());
dro.pop_back();
}
else if (dro.empty()) {
ans.push_back(gau.back());
gau.pop_back();
}
else {
if (quest(gau.back(),dro.back())==1) {
ans.push_back(gau.back());
gau.pop_back();
}
else {
ans.push_back(dro.back());
dro.pop_back();
}
}
}
reverse(ans.begin(),ans.end());
/*for (int i:ans) {
cout<<i<<" ";
}
cout<<endl;*/
return ans;
}
vector<int> Solve(int N) {
nbVal=N;
for (int i=0;i<nbVal;i++) {
for (int j=0;j<nbVal;j++) {
memo[i][j]=-1;
}
}
vector<int> rep,init,ans;
for (int i=0;i<nbVal;i++) {
init.push_back(i);
}
srand(time(NULL));
random_shuffle(init.begin(),init.end());
rep=calc(init);
/*for (int i:rep) {
cout<<i<<" ";
}
cout<<endl;*/
int pos=0,deb,fin;
while (pos<nbVal) {
deb=pos;
if (deb==0) {
vector<int> listeInf;
for (int i=1;i<min(nbVal,50);i++) {
if (quest(rep[0],rep[i])==1) {
listeInf.push_back(i);
//cout<<i<<" ";
}
}
//cout<<endl;
if (listeInf.size()==1) {
fin=listeInf.back();
vector<int> liste2;
for (int i=0;i<min(nbVal,50);i++) {
if (i!=fin and quest(rep[fin],rep[i])==1) {
liste2.push_back(i);
}
}
if (liste2.size()==1) {
fin=0;
}
else {
fin=1;
}
}
else {
listeInf.pop_back();
fin=listeInf.back();
}
pos=fin;
while (deb<fin) {
swap(rep[deb],rep[fin]);
deb++;
fin--;
}
}
else {
while (quest(rep[deb-1],rep[pos])==0) {
pos++;
}
fin=pos;
//cout<<deb<<" "<<fin<<endl;
while (deb<fin) {
swap(rep[deb],rep[fin]);
deb++;
fin--;
}
}
pos++;
}
/*for (int i:rep) {
cout<<i<<" ";
}
cout<<endl;*/
ans.resize(nbVal);
for (int i=0;i<nbVal;i++) {
ans[rep[i]]=i;
}
/*for (int i:ans) {
cout<<i<<" ";
}
cout<<endl;
cout<<"Nombre de questions : "<<nbReq<<endl;*/
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 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 |
1 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 |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
2648 KB |
Output is correct |
17 |
Correct |
7 ms |
2904 KB |
Output is correct |
18 |
Correct |
8 ms |
2904 KB |
Output is correct |
19 |
Correct |
6 ms |
2904 KB |
Output is correct |
20 |
Correct |
8 ms |
2672 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 |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
2904 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
6 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 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 |
1 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 |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
2648 KB |
Output is correct |
17 |
Correct |
7 ms |
2904 KB |
Output is correct |
18 |
Correct |
8 ms |
2904 KB |
Output is correct |
19 |
Correct |
6 ms |
2904 KB |
Output is correct |
20 |
Correct |
8 ms |
2672 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 |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
2904 KB |
Output is correct |
27 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
6 ms |
2904 KB |
Output is correct |
33 |
Correct |
41 ms |
4440 KB |
Output is correct |
34 |
Correct |
48 ms |
4612 KB |
Output is correct |
35 |
Correct |
43 ms |
4440 KB |
Output is correct |
36 |
Correct |
36 ms |
4440 KB |
Output is correct |
37 |
Correct |
41 ms |
4440 KB |
Output is correct |
38 |
Correct |
51 ms |
4432 KB |
Output is correct |
39 |
Correct |
60 ms |
4440 KB |
Output is correct |
40 |
Correct |
50 ms |
4688 KB |
Output is correct |
41 |
Correct |
34 ms |
4644 KB |
Output is correct |
42 |
Correct |
51 ms |
4396 KB |
Output is correct |
43 |
Correct |
57 ms |
4396 KB |
Output is correct |
44 |
Correct |
43 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4440 KB |
Output is correct |
2 |
Correct |
57 ms |
4684 KB |
Output is correct |
3 |
Correct |
36 ms |
4440 KB |
Output is correct |
4 |
Correct |
42 ms |
4440 KB |
Output is correct |
5 |
Correct |
45 ms |
4396 KB |
Output is correct |
6 |
Correct |
35 ms |
4440 KB |
Output is correct |
7 |
Correct |
46 ms |
4628 KB |
Output is correct |
8 |
Correct |
64 ms |
4624 KB |
Output is correct |
9 |
Correct |
51 ms |
4440 KB |
Output is correct |
10 |
Correct |
58 ms |
4440 KB |
Output is correct |
11 |
Correct |
53 ms |
4440 KB |
Output is correct |
12 |
Correct |
55 ms |
4688 KB |
Output is correct |
13 |
Correct |
39 ms |
4396 KB |
Output is correct |
14 |
Correct |
40 ms |
4628 KB |
Output is correct |
15 |
Correct |
34 ms |
4688 KB |
Output is correct |
16 |
Correct |
27 ms |
4688 KB |
Output is correct |
17 |
Correct |
26 ms |
4640 KB |
Output is correct |
18 |
Correct |
47 ms |
4440 KB |
Output is correct |