Submission #1040424

#TimeUsernameProblemLanguageResultExecution timeMemory
1040424nightfalComparing Plants (IOI20_plants)C++14
Compilation error
0 ms0 KiB
#include "plants.h" 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) { 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 (stderr)

plants.cpp: In function 'void print(std::vector<int>&)':
plants.cpp:4:56: error: 'cout' is not a member of 'std'
    4 | void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
      |                                                        ^~~~
plants.cpp:2:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include "plants.h"
  +++ |+#include <iostream>
    2 | static std:: vector<int> inc,dec;
plants.cpp:4:82: error: 'cout' is not a member of 'std'
    4 | void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
      |                                                                                  ^~~~
plants.cpp:4:82: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
plants.cpp:4:95: error: 'endl' is not a member of 'std'
    4 | void print(std::vector<int> &v) {for(int elem: v) std::cout << elem << " "; std::cout << std::endl;}
      |                                                                                               ^~~~
plants.cpp:2:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
    1 | #include "plants.h"
  +++ |+#include <ostream>
    2 | static std:: vector<int> inc,dec;
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:8:22: error: 'n' was not declared in this scope
    8 |       for(int i=0; i<n; i++) {inc[i] = dec[i] = i;}
      |                      ^
plants.cpp:10:18: error: 'n' was not declared in this scope
   10 |       for(s=0; s<n; s++) {if (r[s]==0) break;}
      |                  ^
plants.cpp:11:21: error: 'n' was not declared in this scope
   11 |       for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]) inc[i%n] = inc[(i+1)%n];}
      |                     ^
plants.cpp:12:18: error: 'n' was not declared in this scope
   12 |       for(s=0; s<n; s++) {if (r[s]) break;}
      |                  ^
plants.cpp:13:21: error: 'n' was not declared in this scope
   13 |       for(int i=s-1+n; i>=s+1; i--) {if (r[i%n]==0) dec[i%n] = dec[(i+1)%n];}
      |                     ^
plants.cpp: In function 'int subtask1(int, int)':
plants.cpp:20:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   20 |       if (y<= dec[x] or x<= inc[y] and inc[y] < y) return 1;
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:21:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   21 |       else if (y <= inc[x] or x<= dec[y] and dec[y] < y) return -1;
      |                               ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:24:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   24 |      if (y<= inc[x] or x<= dec[y] and dec[y] < y) return 1;
      |                        ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:25:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   25 |       else if (y <= dec[x] or x<= inc[y] and inc[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);
      |        ^