Submission #434462

#TimeUsernameProblemLanguageResultExecution timeMemory
434462rqiComparing Plants (IOI20_plants)C++17
5 / 100
115 ms10200 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> pi; #define mp make_pair #define f first #define s second #define sz(x) (int)(x).size() const int mx = 200005; pi rangs[mx][2]; void init(int k, vi r) { int n = sz(r); int start = 0; for(int i = 0; i < n; i++){ if(r[i] != r[0]){ start = i; break; } } int cur = start; while(true){ int end_ind = cur; while(r[(end_ind+1) % n] == r[cur]){ end_ind = (end_ind+1) % n; } pi interval = mp(cur, (end_ind+1) % n); // cout << cur << " " << end_ind << "\n"; // cout << interval.f << " " << interval.s << "\n"; for(int i = cur; ; (i = (i+1) % n)){ if(i == cur){ rangs[i][1] = mp(r[cur], interval.s); } else if(i == (end_ind+1) % n){ rangs[i][0] = mp(r[cur], interval.f); break; } else{ rangs[i][0] = mp(r[cur], interval.f); rangs[i][1] = mp(r[cur], interval.s); } } cur = (end_ind+1) % n; if(cur == start) break; } return; } bool isInInterval(int test, int int_beg, int int_end){ if(int_beg <= int_end){ return (int_beg <= test) && (test <= int_end); } return (int_beg <= test) || (test <= int_end); } int compare_plants(int x, int y) { if(isInInterval(y, rangs[x][0].s, x)){ if(rangs[x][0].f == 1){ return 1; } else{ return -1; } } else if(isInInterval(y, x, rangs[x][1].s)){ if(rangs[x][1].f == 1){ return -1; } else{ return 1; } } 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...