제출 #1133286

#제출 시각아이디문제언어결과실행 시간메모리
1133286alterio식물 비교 (IOI20_plants)C++20
5 / 100
46 ms5100 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; const int mxn = 2e5 + 100; int n, k; int prf[mxn]; int get(int l, int r) { return prf[r] - (l ? prf[l - 1] : 0); } void init(int _k, vector<int> r) { k = _k; n = r.size(); for (int i = 0; i < n; i++) prf[i] = (i ? prf[i - 1] : 0) + (r[i] == 1 ? -1 : 1); } // 1 > : -1 < : 0 ? int compare_plants(int x, int y) { int mult = 1; if (x > y) swap(x, y), mult = -1; int ans1 = 0, ans2 = 0; int sum = get(x, y - 1); if (abs(sum) == y - x) ans1 = sum / abs(sum); sum = get(y, n - 1); if (x) sum += get(0, x - 1); if (abs(sum) == (n - y + x)) ans2 = -(sum / abs(sum)); int ans = ans1; if (ans1 == 0) ans = ans2; else if (ans2 == 0) ans = ans1; else if (ans1 != ans2) ans = 0; return ans * mult; }
#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...