Submission #1040881

#TimeUsernameProblemLanguageResultExecution timeMemory
1040881nightfalComparing Plants (IOI20_plants)C++14
Compilation error
0 ms0 KiB
static std:: vector<int> inc,dec,rank; static int l,m; // void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;} int findMax(int k, std::vector<int> &r) { int i=2*n-1; while (r[i%n]!=0) {i--;} // std::cout << i << std::endl; int j = i-1; while (j > i-k) { if (r[j%n]==0) i = j; j--; } for(int j=i; j>i-k; j--) r[j%n]--; // std::cout << i%n << std::endl; // print(r); return i%n; } void init2(int k, std::vector<int> r) { n = r.size(); rank.resize(n); for(int i=n-1; i>=0; i--) { rank[findMax(k,r)] = i; // print(rank); } return; } int compare_plants2(int x, int y) { if (rank[x]>rank[y]) return 1; else return -1; } void init1(int k, std::vector<int> r) { int n = r.size(); inc.resize(n); dec.resize(n); for(int i=0; i<n; i++) {inc[i] = dec[i] = i;} int s,incVal,decVal; for(s=2*n-1; s>=0; s--) { if (r[s%n]==0) incVal = s; else decVal = s; inc[s%n] = incVal; dec[s%n] = decVal; } return; } int compare_plants1(int x, int y) { if (y <= dec[x] or x+n <= inc[y]) return 1; else if (y <= inc[x] or x+n <= dec[y]) return -1; return 0; } void init(int k, std::vector<int> r) { int n = r.size(); m=n; l=k; if(k==2) init1(k, r); if(n<=5000 and 2*k>n) init2(k, r); return; } int compare_plants(int x, int y) { if(l==2) return compare_plants1(x,y); if(m<=5000 and 2*l>m) return compare_plants2(x,y); return 0; }

Compilation message (stderr)

plants.cpp:1:14: error: 'vector' in namespace 'std' does not name a template type
    1 | static std:: vector<int> inc,dec,rank;
      |              ^~~~~~
plants.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | static std:: vector<int> inc,dec,rank;
plants.cpp:5:25: error: 'std::vector' has not been declared
    5 | int findMax(int k, std::vector<int> &r) {
      |                         ^~~~~~
plants.cpp:5:31: error: expected ',' or '...' before '<' token
    5 | int findMax(int k, std::vector<int> &r) {
      |                               ^
plants.cpp: In function 'int findMax(int, int)':
plants.cpp:6:13: error: 'n' was not declared in this scope
    6 |     int i=2*n-1;
      |             ^
plants.cpp:7:12: error: 'r' was not declared in this scope
    7 |     while (r[i%n]!=0) {i--;}
      |            ^
plants.cpp:11:13: error: 'r' was not declared in this scope
   11 |         if (r[j%n]==0) i = j;
      |             ^
plants.cpp:14:30: error: 'r' was not declared in this scope
   14 |     for(int j=i; j>i-k; j--) r[j%n]--;
      |                              ^
plants.cpp: At global scope:
plants.cpp:19:24: error: 'std::vector' has not been declared
   19 | void init2(int k, std::vector<int> r) {
      |                        ^~~~~~
plants.cpp:19:30: error: expected ',' or '...' before '<' token
   19 | void init2(int k, std::vector<int> r) {
      |                              ^
plants.cpp: In function 'void init2(int, int)':
plants.cpp:20:5: error: 'n' was not declared in this scope
   20 |     n = r.size();
      |     ^
plants.cpp:20:9: error: 'r' was not declared in this scope
   20 |     n = r.size();
      |         ^
plants.cpp:21:5: error: 'rank' was not declared in this scope
   21 |     rank.resize(n);
      |     ^~~~
plants.cpp: In function 'int compare_plants2(int, int)':
plants.cpp:29:9: error: 'rank' was not declared in this scope
   29 |     if (rank[x]>rank[y]) return 1;
      |         ^~~~
plants.cpp: At global scope:
plants.cpp:32:24: error: 'std::vector' has not been declared
   32 | void init1(int k, std::vector<int> r) {
      |                        ^~~~~~
plants.cpp:32:30: error: expected ',' or '...' before '<' token
   32 | void init1(int k, std::vector<int> r) {
      |                              ^
plants.cpp: In function 'void init1(int, int)':
plants.cpp:33:13: error: 'r' was not declared in this scope
   33 |     int n = r.size();
      |             ^
plants.cpp:34:5: error: 'inc' was not declared in this scope; did you mean 'int'?
   34 |     inc.resize(n); dec.resize(n);
      |     ^~~
      |     int
plants.cpp:34:20: error: 'dec' was not declared in this scope
   34 |     inc.resize(n); dec.resize(n);
      |                    ^~~
plants.cpp: In function 'int compare_plants1(int, int)':
plants.cpp:45:14: error: 'dec' was not declared in this scope
   45 |     if (y <= dec[x] or x+n <= inc[y]) return 1;
      |              ^~~
plants.cpp:45:26: error: 'n' was not declared in this scope
   45 |     if (y <= dec[x] or x+n <= inc[y]) return 1;
      |                          ^
plants.cpp:45:31: error: 'inc' was not declared in this scope; did you mean 'int'?
   45 |     if (y <= dec[x] or x+n <= inc[y]) return 1;
      |                               ^~~
      |                               int
plants.cpp: At global scope:
plants.cpp:49:23: error: 'std::vector' has not been declared
   49 | void init(int k, std::vector<int> r) {
      |                       ^~~~~~
plants.cpp:49:29: error: expected ',' or '...' before '<' token
   49 | void init(int k, std::vector<int> r) {
      |                             ^
plants.cpp: In function 'void init(int, int)':
plants.cpp:50:13: error: 'r' was not declared in this scope
   50 |     int n = r.size();
      |             ^
plants.cpp: In function 'int compare_plants2(int, int)':
plants.cpp:31:1: warning: control reaches end of non-void function [-Wreturn-type]
   31 | }
      | ^