제출 #1166010

#제출 시각아이디문제언어결과실행 시간메모리
1166010irmuun식물 비교 (IOI20_plants)C++20
5 / 100
50 ms5704 KiB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

int n,k;
vector<int>r,pre,h;

int get(int x,int y){
    if(x>y) return 0;
    return pre[y]-(x>0?pre[x-1]:0);
}

void init(int K,vector<int>R){
    k=K;
    r=R;
    n=r.size();
    pre.resize(n);
    pre[0]=r[0];
    for(int i=1;i<n;i++){
        pre[i]=pre[i-1]+r[i];
    }
    if(2*k>n){
        h.resize(n);
        for(int t=n;t>=1;t--){
            for(int i=0;i<n;i++){
                if(h[i]==0&&r[i]==0){
                    h[i]=t;
                    for(int j=1;j<k;j++){
                        r[(i-j+n)%n]--;
                    }
                    break;
                }
            }
        }
    }
}

int compare_plants(int x,int y){
    if(k==2){
        if(get(x,y-1)==0) return 1;
        if(get(y,n-1)==n-y&&get(0,x-1)==x) return 1;
        if(get(x,y-1)==y-x) return -1;
        if(get(y,n-1)==0&&get(0,x-1)==0) return -1;
        return 0;
    }
    if(2*k>n){
        if(h[x]>h[y]) return 1;
        if(h[x]<h[y]) return -1;
        return 0;
    }
    return 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...