Submission #421317

#TimeUsernameProblemLanguageResultExecution timeMemory
421317JUANDI321Comparing Plants (IOI20_plants)C++17
Compilation error
0 ms0 KiB
#include "plants.h" #include <vector> #include <iostream> using namespace std; int sumpf[200010], copyr[20010]; int n; void init(int k, vector<int> r) { n = r.size(); sumpf[0] = 200010; //cout<<sumpf[1]<<" "; copyr[0] = r[0]; for(int i = 1; i < r.size(); i++) { sumpf[i] = sumpf[i-1] + r[i-1]; if(r[i-1] == 0) sumpf[i]--; copyr[i] = r[i]; // cout<<sumpf[i+1]<<" "; } //cout<<endl; return; } int compare_plants(int x, int y) { if(x == 0 && y == n-1) { if(copyr[n-1] == 1) return 1; return -1; } int dis = y-x+1; //cout<<dis<<endl; //cout<<sumpf[y]-sumpf[x-1]<<endl; int sum = sumpf[y] - sumpf[x-1]; if(x == 0)sum = sumpf[y]; if(sum == dis) return 1; if(sum == -1 * dis) return -1; dis = n - y + x +1; sum = sum[n-1] - sumpf[y-1] + sumpf[x]; //if(x == 0)sum = sumpf[y]; if(sum == dis) return 1; if(sum == -1 * dis) return -1; return 0; }

Compilation message (stderr)

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for(int i = 1; i < r.size(); i++)
      |                 ~~^~~~~~~~~~
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:40:11: error: invalid types 'int[int]' for array subscript
   40 |  sum = sum[n-1] - sumpf[y-1] + sumpf[x];
      |           ^