Submission #1040432

# Submission time Handle Problem Language Result Execution time Memory
1040432 2024-08-01T03:58:04 Z nightfal Comparing Plants (IOI20_plants) C++14
Compilation error
0 ms 0 KB
static std:: vector<int> inc,dec;

// void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
void init(int k, std::vector<int> r) {
    int n = r.size();
	if(k==2) {
      inc.resize(n); dec.resize(n);
      for(int i=0; i<n; i++) {inc[i] = dec[i] = i;}
      int s;
      for(s=0; s<n; s++) {if (r[s]==0) break;}
      for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]) inc[i%n] = inc[(i+1)%n];}
      for(s=0; s<n; s++) {if (r[s]) break;}
      for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]==0) dec[i%n] = dec[(i+1)%n];}      	          
    //   print(inc); print(dec);
    }
	return;
}
int subtask1(int x, int y) {
	if (x<y) {
      if (y<= dec[x] or x<= inc[y] and inc[y] < y) return 1;
      else if (y <= inc[x] or x<= dec[y] and dec[y] < y) return -1;
    }
  	else {
  	  if (y<= inc[x] or x<= dec[y] and dec[y] < y) return 1;
      else if (y <= dec[x] or x<= inc[y] and inc[y] < y) return -1;
    }
	return 0;
}
int compare_plants(int x, int y) {
  	if (k==2) return subtask1(x,y);
	return 0;
}

Compilation message

plants.cpp:1:14: error: 'vector' in namespace 'std' does not name a template type
    1 | static std:: vector<int> inc,dec;
      |              ^~~~~~
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;
plants.cpp:4:23: error: 'std::vector' has not been declared
    4 | void init(int k, std::vector<int> r) {
      |                       ^~~~~~
plants.cpp:4:29: error: expected ',' or '...' before '<' token
    4 | void init(int k, std::vector<int> r) {
      |                             ^
plants.cpp: In function 'void init(int, int)':
plants.cpp:5:13: error: 'r' was not declared in this scope
    5 |     int n = r.size();
      |             ^
plants.cpp:7:7: error: 'inc' was not declared in this scope; did you mean 'int'?
    7 |       inc.resize(n); dec.resize(n);
      |       ^~~
      |       int
plants.cpp:7:22: error: 'dec' was not declared in this scope
    7 |       inc.resize(n); dec.resize(n);
      |                      ^~~
plants.cpp: In function 'int subtask1(int, int)':
plants.cpp:20:15: error: 'dec' was not declared in this scope
   20 |       if (y<= dec[x] or x<= inc[y] and inc[y] < y) return 1;
      |               ^~~
plants.cpp:20:29: error: 'inc' was not declared in this scope; did you mean 'int'?
   20 |       if (y<= dec[x] or x<= inc[y] and inc[y] < y) return 1;
      |                             ^~~
      |                             int
plants.cpp:24:14: error: 'inc' was not declared in this scope; did you mean 'int'?
   24 |      if (y<= inc[x] or x<= dec[y] and dec[y] < y) return 1;
      |              ^~~
      |              int
plants.cpp:24:28: error: 'dec' was not declared in this scope
   24 |      if (y<= inc[x] or x<= dec[y] and dec[y] < y) return 1;
      |                            ^~~
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:30:8: error: 'k' was not declared in this scope
   30 |    if (k==2) return subtask1(x,y);
      |        ^