Submission #359950

#TimeUsernameProblemLanguageResultExecution timeMemory
359950SortingComparing Plants (IOI20_plants)C++17
5 / 100
97 ms7276 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; int r[N], cnt[N], k, n; void init(int _k, vector<int> _r) { k = _k; n = _r.size(); for(int i = 0; i < _r.size(); ++i) r[i] = _r[i]; cnt[0] = 1; for(int i = 1; i < n; ++i) cnt[i] = (r[i] == r[i - 1]) ? cnt[i - 1] + 1 : 1; if(r[0] == r[n - 1] && cnt[n - 1] != n){ int i = 0; while(r[i] == r[0]){ cnt[i] += cnt[n - 1]; i++; } } } int compare_plants(int x, int y) { if(cnt[y - 1] >= y - x) return r[x] ? -1 : 1; if(cnt[(x - 1 + n) % n] >= x + n - y) return r[y] ? 1 : -1; return 0; }

Compilation message (stderr)

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < _r.size(); ++i)
      |                    ~~^~~~~~~~~~~
#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...