# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706575 | asdfasdfasdfasdf | Minerals (JOI19_minerals) | C++14 | 76 ms | 3580 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 "minerals.h"
#include <bits/stdc++.h>
using namespace std;
int match[111111];
vector<int> group[2];
void Divide(vector<int> A, vector<int> B, int c)
{
random_shuffle(A.begin(),A.end());
random_shuffle(B.begin(),B.end());
if(A.size()==0)
return;
if(A.size()==1)
{
match[A[0]]=B[0];
match[B[0]]=A[0];
return;
}
int pre=0;
int sz=A.size()/2;
if(sz==0)
sz++;
if(sz==A.size())
sz--;
vector<int> A1;
vector<int> A2;
vector<int> B1;
vector<int> B2;
if(c==1)
{
for(int i=0;i<sz;i++)
pre=Query(A[i]+1);
for(int i=0;i<A.size();i++)
{
if(i<sz)
A1.push_back(A[i]);
else
A2.push_back(A[i]);
}
for(int i=0;i<B.size();i++)
{
if(A1.size()==B1.size())
B2.push_back(B[i]);
else if(A2.size()==B2.size())
B1.push_back(B[i]);
else
{
int tmp=Query(B[i]+1);
if(pre!=tmp)
B1.push_back(B[i]);
else
B2.push_back(B[i]);
pre=tmp;
}
}
}
else
{
for(int i=sz;i<A.size();i++)
pre=Query(A[i]+1);
for(int i=0;i<A.size();i++)
{
if(i<sz)
A1.push_back(A[i]);
else
A2.push_back(A[i]);
}
for(int i=0;i<B.size();i++)
{
if(A1.size()==B1.size())
B2.push_back(B[i]);
else if(A2.size()==B2.size())
B1.push_back(B[i]);
else
{
int tmp=Query(B[i]+1);
if(pre!=tmp)
B1.push_back(B[i]);
else
B2.push_back(B[i]);
pre=tmp;
}
}
}
Divide(A1,B1,0);
Divide(A2,B2,1);
return;
}
void Solve(int n)
{
int pre=0;
for(int i=0;i<n*2;i++)
{
int tmp=Query(i+1);
if(pre<tmp)
group[0].push_back(i);
else
group[1].push_back(i);
pre=tmp;
}
Divide(group[0],group[1],1);
for(int i=0;i<n;i++)
Answer(group[0][i]+1,match[group[0][i]]+1);
return;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |