제출 #866172

#제출 시각아이디문제언어결과실행 시간메모리
866172andrei_boaca식물 비교 (IOI20_plants)C++17
14 / 100
4053 ms23892 KiB
#include "plants.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
vector<int> muchii[200005];
int n,bigger[200005],smaller[200005],lastsmall[200005],lastbig[200005],k,v[200005];
bool use[200005];
ll mars[500005],can[500005];
int dist(int a,int b)
{
    return (b-a+n)%n;
}
int myprv(int x)
{
    return (x-1+n)%n;
}
void init(int K, std::vector<int> r)
{
    n=r.size();
    k=K;
    for(int i=0;i<n;i++)
    {
        lastbig[i]=-1;
        lastsmall[i]=-1;
    }
    for(int i=0;i<n;i++)
    {
        if(r[i]==0)
        {
            int j=(i-1+n)%n;
            while(r[j]==1)
            {
                lastsmall[j]=i;
                j=(j-1+n)%n;
            }
        }
        if(r[i]==1)
        {
            int j=(i-1+n)%n;
            while(r[j]==0)
            {
                lastbig[j]=i;
                j=(j-1+n)%n;
            }
        }
    }
    for(int value=1;value<=n;value++)
    {
        for(int i=0;i<=2*n;i++)
        {
            mars[i]=0;
            can[i]=0;
        }
        for(int j=0;j<n;j++)
            if(!use[j])
            {
                if(r[j]==k-1)
                {
                    mars[j+1]++;
                    mars[j+k]--;
                }
                else
                    can[j]++;
            }
        bool ok=0;
        if(value==2)
            ok=1;
        for(int j=0;j<2*n;j++)
        {
            if(j>0)
                mars[j]+=mars[j-1];
            can[j%n]+=mars[j];
        }
        int who=-1;
        for(int j=0;j<n;j++)
            if(can[j]==0&&!use[j])
            {
                who=j;
                break;
            }
        assert(who>-1);
        use[who]=1;
        v[who]=value;
        for(int j=myprv(who),cnt=1;cnt<k;cnt++,j=myprv(j))
            r[j]++;
    }
}
int compare_plants(int x, int y)
{
    if(k==2)
    {
        if(lastsmall[x]!=-1&&dist(x,y)+dist(y,lastsmall[x])==dist(x,lastsmall[x]))
            return -1;
        if(lastbig[x]!=-1&&dist(x,y)+dist(y,lastbig[x])==dist(x,lastbig[x]))
            return 1;
        if(lastsmall[y]!=-1&&dist(y,x)+dist(x,lastsmall[y])==dist(y,lastsmall[y]))
            return 1;
        if(lastbig[y]!=-1&&dist(y,x)+dist(x,lastbig[y])==dist(y,lastbig[y]))
            return -1;
        return 0;
    }
    if(v[x]<v[y])
        return -1;
    if(v[x]>v[y])
        return 1;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:66:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   66 |         bool ok=0;
      |              ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...