# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1053918 | Itamar | Monster Game (JOI21_monster) | C++17 | 62 ms | 672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<vector>
using namespace std;
#define vi vector<int>
bool Query(int a, int b);
void sorti(vi &v){
vi v1,v2;
int s = v.size();
if(s==1)return;
for(int i = 0; i <s/2; i++ )v1.push_back(v[i]);
for(int i = s/2; i < s; i++)v2.push_back(v[i]);
sorti(v1);
sorti(v2);
vi vt;
int it = 0;
for(int i= 0; i < s/2; i++){
while(it < v2.size() && !Query(v2[it],v1[i])){
vt.push_back(v2[it]);
it++;
}vt.push_back(v1[i]);
}
while(it < v2.size()){
vt.push_back(v2[it]);
it++;
}
v=vt;
}
int n;
int find(int ind){
int sum = 0;
vi win,lose;
for(int i = 0; i < n; i++){
if(ind == i)continue;
if(Query(ind,i))win.push_back(i);
else lose.push_back(i);
}
if(win.size()==1){
int sum = 0;
for(int i = 0; i < n; i++){
if(i!=win[0]){
sum += Query(win[0],i);
if(sum == 2)return 1;
}
}
return 0;
}else if(lose.size() == 1){
int sum = 0;
for(int i = 0; i < n; i++){
if(i!=lose[0]){
sum += Query(i,lose[0]);
if(sum == 2)return n-2;
}
}
return n-1;
}else{
return win.size();
}
}
std::vector<int> Solve(int N) {
n=N;
std::vector<int> ans;
vi v; for(int i = 0; i <N; i++)v.push_back(i);
sorti(v);
vi res(N);
int l = 0,r = find(v[0]);
for(int i = r; i>=0; i--)ans.push_back(i);
while(ans.size()<N){
int lt = r+1;
for(int i = lt; i < N; i++){
if(Query(v[l],v[i])){
l = lt;
r = i;
for(int j = r; j>=l; j--)ans.push_back(j);
break;
}
}
}
for(int i = 0; i < N; i++){
res[v[i]] = ans[i];
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |