Submission #1040433

# Submission time Handle Problem Language Result Execution time Memory
1040433 2024-08-01T03:59:24 Z nightfal Comparing Plants (IOI20_plants) C++14
Compilation error
0 ms 0 KB
#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) {
    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: In function 'int subtask1(int, int)':
plants.cpp:21:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   21 |       if (y<= dec[x] or x<= inc[y] and inc[y] < y) return 1;
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:22:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |       else if (y <= inc[x] or x<= dec[y] and dec[y] < y) return -1;
      |                               ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:25:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   25 |      if (y<= inc[x] or x<= dec[y] and dec[y] < y) return 1;
      |                        ~~~~~~~~~~~^~~~~~~~~~~~~~
plants.cpp:26:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |       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:31:8: error: 'k' was not declared in this scope
   31 |    if (k==2) return subtask1(x,y);
      |        ^