제출 #589420

#제출 시각아이디문제언어결과실행 시간메모리
589420Lucpp식물 비교 (IOI20_plants)C++17
5 / 100
77 ms6560 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; const int INF = 1e8; int n, k; vector<int> dpL, dpR; void init_k2(vector<int> r){ dpL.resize(n), dpR.resize(n); for(int it = 0; it < 2; it++){ for(int i = n-1; i >= 0; i--){ if(r[i]) dpR[i] = dpR[(i+1)%n]+1; } for(int i = 0; i < n; i++){ if(!r[(i+n-1)%n]) dpL[i] = dpL[(i+n-1)%n]+1; } } } vector<int> h; void init_else(vector<int> r){ h.resize(n); for(int it = 0; it < n; it++){ for(int i = 0; i < n; i++){ if(r[i] == 0){ h[i] = n-it; r[i] = INF; for(int j = (i-k+1+n)%n; j != i; j=(j+1)%n) r[j]--; break; } } } } void init(int K, vector<int> r) { k = K; n = (int)r.size(); if(k == 2) init_k2(r); else init_else(r); } int compare_k2(int x, int y){ int d1 = (y-x+n)%n; int d2 = n-d1; if(dpR[x] >= d1 || dpL[x] >= d2) return -1; if(dpR[y] >= d2 || dpL[y] >= d1) return 1; return 0; } int compare_else(int x, int y){ if(h[x] < h[y]) return -1; else return 1; } int compare_plants(int x, int y) { if(k == 2) return compare_k2(x, y); else return compare_else(x, y); }
#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...