#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<nbVal;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<nbVal;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 |
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 |
1 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 |
7 ms |
2904 KB |
Output is correct |
17 |
Correct |
7 ms |
2904 KB |
Output is correct |
18 |
Correct |
7 ms |
2900 KB |
Output is correct |
19 |
Correct |
10 ms |
2904 KB |
Output is correct |
20 |
Correct |
11 ms |
2648 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
2904 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 |
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 |
9 ms |
2904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 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 |
7 ms |
2904 KB |
Output is correct |
17 |
Correct |
7 ms |
2904 KB |
Output is correct |
18 |
Correct |
7 ms |
2900 KB |
Output is correct |
19 |
Correct |
10 ms |
2904 KB |
Output is correct |
20 |
Correct |
11 ms |
2648 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
2904 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 |
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 |
9 ms |
2904 KB |
Output is correct |
33 |
Correct |
66 ms |
4440 KB |
Output is correct |
34 |
Correct |
73 ms |
4440 KB |
Output is correct |
35 |
Correct |
51 ms |
4620 KB |
Output is correct |
36 |
Correct |
57 ms |
4440 KB |
Output is correct |
37 |
Correct |
52 ms |
4440 KB |
Output is correct |
38 |
Correct |
57 ms |
4440 KB |
Output is correct |
39 |
Correct |
70 ms |
4396 KB |
Output is correct |
40 |
Correct |
59 ms |
4392 KB |
Output is correct |
41 |
Correct |
58 ms |
4440 KB |
Output is correct |
42 |
Correct |
52 ms |
4440 KB |
Output is correct |
43 |
Correct |
48 ms |
4432 KB |
Output is correct |
44 |
Correct |
56 ms |
4388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
51 ms |
4440 KB |
Partially correct |
2 |
Partially correct |
53 ms |
4396 KB |
Partially correct |
3 |
Partially correct |
55 ms |
4440 KB |
Partially correct |
4 |
Partially correct |
60 ms |
4440 KB |
Partially correct |
5 |
Partially correct |
50 ms |
4648 KB |
Partially correct |
6 |
Partially correct |
40 ms |
4400 KB |
Partially correct |
7 |
Correct |
40 ms |
4440 KB |
Output is correct |
8 |
Partially correct |
60 ms |
4388 KB |
Partially correct |
9 |
Partially correct |
70 ms |
4620 KB |
Partially correct |
10 |
Partially correct |
57 ms |
4440 KB |
Partially correct |
11 |
Partially correct |
64 ms |
4440 KB |
Partially correct |
12 |
Partially correct |
63 ms |
4392 KB |
Partially correct |
13 |
Partially correct |
53 ms |
4436 KB |
Partially correct |
14 |
Partially correct |
54 ms |
4440 KB |
Partially correct |
15 |
Correct |
38 ms |
4628 KB |
Output is correct |
16 |
Correct |
49 ms |
4432 KB |
Output is correct |
17 |
Correct |
35 ms |
4396 KB |
Output is correct |
18 |
Partially correct |
63 ms |
4440 KB |
Partially correct |