Submission #420395

#TimeUsernameProblemLanguageResultExecution timeMemory
420395idk321Comparing Plants (IOI20_plants)C++11
Compilation error
0 ms0 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; int k; vector<int> r; vector<int> prefR; int n; int getSum(int from, int to) { int res = prefR[to + 1]; res -= prefR[from]; return res; } void init(int K, std::vector<int> R) { k = K; r = R; n = r.size(); prefR.resize(r.size() + 1) for (int i = 1; i <= r.size(); i++) { prefR[i] = r[i - 1]; prefR[i] += prefR[i - 1]; } return; } int compare_plants(int x, int y) { if (k == 2) { if (getSum(x, y - 1) == (y - x)) return -1; if (getSum(x, y - 1) == 0) return 1; int sum1 = getSum(y, n -1); if (x != 0) sum1 += getSum(0, x - 1); if (sum1 == (n - y) + x) return 1; if (sum1 == 0) return -1; return 0; } return 0; }

Compilation message (stderr)

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:21:31: error: expected ';' before 'for'
   21 |     prefR.resize(r.size() + 1)
      |                               ^
      |                               ;
   22 |     for (int i = 1; i <= r.size(); i++)
      |     ~~~                        
plants.cpp:22:21: error: 'i' was not declared in this scope
   22 |     for (int i = 1; i <= r.size(); i++)
      |                     ^