Submission #1073057

#TimeUsernameProblemLanguageResultExecution timeMemory
1073057TheQuantiXComparing Plants (IOI20_plants)C++17
5 / 100
55 ms11468 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; using ll = long long; ll n, m, q, k, x, y, a, b, c; int tc; vector<ll> vec; void init(int k, vector<int> r) { n = r.size(); if (k == 2) { tc = 1; vec.push_back(0); for (int i = 0; i < n; i++) { vec.push_back(r[i]); } for (int i = 0; i < n; i++) { vec.push_back(r[i]); } for (int i = 1; i < 2 * n; i++) { vec[i] += vec[i - 1]; } } else if (k * 2 > n) { tc = 3; vec.resize(n); set<ll> st; for (int i = 0; i < n; i++) { if (r[i] == 0) { st.insert(i); } } ll x = (*st.begin()); for (int i = n - 1; i >= 0; i--) { vec[x] = i; st.erase(x); // cout << x << endl; for (int j = 1; j < k; j++) { // cout << j << ' ' << (x - j + n) % n << '\n'; if (r[(x - j + n) % n] == 1) { st.insert((x - j + n) % n); } if (r[(x - j + n) % n] != 0) { r[(x - j + n) % n]--; } } if (st.size() != 0) { for (int j : st) { // cout << j << ' ' << '\n'; if (st.find(j) == (--st.end()) && (*st.begin()) + n - j >= k) { x = (*st.begin()); break; } if (st.find(j) != (--st.end()) && (*st.upper_bound(j)) - j >= k) { x = (*st.upper_bound(j)); break; } } } } } } int compare_plants(int x, int y) { if (tc == 1) { if (vec[y] - vec[x] == y - x) { return -1; } if (vec[y] - vec[x] == 0) { return 1; } if (vec[(n + x)] - vec[y] == (n + x) - y) { return 1; } if (vec[(n + x)] - vec[y] == 0) { return -1; } return 0; } if (tc == 3) { if (vec[y] > vec[x]) { return -1; } return 1; } }

Compilation message (stderr)

plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
   88 | }
      | ^
#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...