# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
864720 | andrei_boaca | Comparing Plants (IOI20_plants) | C++17 | 125 ms | 223784 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 "plants.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
vector<int> muchii[200005];
int rel[5005][5005],n,bigger[200005],smaller[200005];
bool reach[5005][5005];
bool use[200005];
void dfs(int nod,int start)
{
reach[start][nod]=1;
for(int i:muchii[nod])
if(!reach[start][i])
dfs(i,start);
}
void init(int k, std::vector<int> r)
{
n=r.size();
queue<int> coada;
for(int i=0;i<r.size();i++)
{
bigger[i]=r[i];
smaller[i]=k-1-r[i];
if(bigger[i]==0||smaller[i]==0)
coada.push(i);
}
while(!coada.empty())
{
int nod=coada.front();
use[nod]=1;
coada.pop();
for(int i=(nod+1)%n,cnt=1;cnt<k;cnt++,i=(i+1)%n)
if(rel[nod][i]==0)
{
if(smaller[nod])
{
smaller[nod]--;
rel[nod][i]=1;
muchii[i].push_back(nod);
rel[i][nod]=-1;
if((nod-i+n)%n<k)
bigger[i]--;
}
else
{
bigger[nod]--;
muchii[nod].push_back(i);
rel[nod][i]=-1;
rel[i][nod]=1;
if((nod-i+n)%n<k)
smaller[i]--;
}
if(bigger[i]==0||smaller[i]==0)
if(!use[i])
{
use[i]=1;
coada.push(i);
}
}
}
for(int i=0;i<n;i++)
dfs(i,i);
}
int compare_plants(int x, int y) {
if(reach[x][y])
return -1;
if(reach[y][x])
return 1;
return 0;
}
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... |