#include "monster.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
#ifdef LOCAL
#define debug(v) for(auto x: v) cerr << x << " "; cerr << #v << "\n";
#endif
vector<vector<int>> QQ;
bool query(int a, int b){
if(a > b){
if(QQ[b][a] == -1) QQ[b][a] = Query(b, a);
return !QQ[b][a];
}
else{
if(QQ[a][b] == -1) QQ[a][b] = Query(a, b);
return QQ[a][b];
}
}
template<typename it>
void merge_sort(it a, it b){
int n = b-a;
if(n == 1) return;
merge_sort(a, a+n/2);
merge_sort(a+n/2, b);
int* ab = new int[n];
merge(a, a+n/2, a+n/2, b, ab, [&](int x, int y){
return query(y, x);
});
for(int i = 0; i < n; i++) *(a+i) = *(ab+i);
}
vector<int> Solve(int n){
QQ = vector<vector<int>>(n, vector<int>(n, -1));
vector<int> sth(n);
for(int i = 0; i < n; i++) sth[i] = i;
merge_sort(sth.begin(), sth.end());
auto win = [=](int x){
vector<int> rt;
for(int i = 0; i < n; i++) if(i != x && query(x, i)) rt.pb(i);
return rt;
};
int n0 = n;
if(win(sth[n-1]).size() == n-2 && win(sth[n-2]).size() != n-2) n0--;
for(int i = 0; i < n0-1; i++){
if(i == 0){
auto s0 = win(sth[0]);
if(s0.size() == 1){
auto s1 = win(s0[0]);
if(s1.size() == 1) continue;
}
}
bool bl = 0;
for(int j = i+2; j < n0; j++){
if(query(sth[j], sth[i])){
reverse(sth.begin()+i, sth.begin()+j);
i = j-1;
bl = 1;
break;
}
}
if(!bl){
reverse(sth.begin()+i, sth.begin()+n0);
i = n;
}
}
vector<int> ans(n);
for(int i = 0; i < n; i++) ans[sth[i]] = i;
return ans;
}
Compilation message
monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:53:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if(win(sth[n-1]).size() == n-2 && win(sth[n-2]).size() != n-2) n0--;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~
monster.cpp:53:60: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if(win(sth[n-1]).size() == n-2 && win(sth[n-2]).size() != n-2) n0--;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Incorrect |
2 ms |
200 KB |
Wrong Answer [3] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
2 ms |
200 KB |
Output is correct |
7 |
Incorrect |
2 ms |
200 KB |
Wrong Answer [3] |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
116 ms |
4236 KB |
Wrong Answer [3] |
2 |
Halted |
0 ms |
0 KB |
- |