Submission #359958

#TimeUsernameProblemLanguageResultExecution timeMemory
359958SortingComparing Plants (IOI20_plants)C++17
0 / 100
65 ms4984 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 3; int r[N], p[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]; for(int i = n - 1; i >= 0; --i){ int prev = n, idx; bool ok = false; for(int j = n - 1; j >= 0; --j){ if(prev - j >= k && prev != n){ idx = prev; ok = true; break; } if(!r[j]) prev = j; } if(!ok){ for(int j = n - 1; j >= 0; --j) if(!r[j]){ idx = j; break; } } p[idx] = i; r[idx] = n; for(int j = 1; j <= k - 1; ++j) r[(idx - j + n) % n]--; } } int compare_plants(int x, int y) { return (p[x] > p[y]) ? 1 : -1; }

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)
      |                    ~~^~~~~~~~~~~
plants.cpp:17:23: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   17 |         int prev = n, idx;
      |                       ^~~
#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...