Submission #768985

# Submission time Handle Problem Language Result Execution time Memory
768985 2023-06-29T04:01:59 Z ono_de206 Comparing Plants (IOI20_plants) C++14
Compilation error
0 ms 0 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

vector<int> a, pre;

void init(int _k, vector<int> r) {
	k = _k;
	int n = r.size();
	pre.resize(n * 3);
	for(int i = 0; i < 3; i++) {
		a.in(a.end(), all(r));
	}
	pre[0] = a[0];
	for(int i = 0; i + 1 < n * 3; i++) {
		pre[i + 1] = pre[i] + a[i + 1];
	}
}

int compare_plants(int x, int y) {
	if(x < y) {
		int sum = pre[y - 1] - (x == 0 ? 0 : pre[x - 1]);
		if(sum == y - x) return -1;
		sum = pre[x + n - 1] - pre[y - 1];
		if(sum == x + n - y) return 1;
	} else {
		int sum = pre[y + n - 1] - pre[x - 1];
		if(sum == y + n - x) return -1;
		sum = pre[x - 1] - (y == 0 ? 0 : pre[y - 1]);
		if(sum == x - y) return 1;
	}
	return 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:24:2: error: 'k' was not declared in this scope; did you mean '_k'?
   24 |  k = _k;
      |  ^
      |  _k
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:40:17: error: 'n' was not declared in this scope
   40 |   sum = pre[x + n - 1] - pre[y - 1];
      |                 ^
plants.cpp:43:21: error: 'n' was not declared in this scope
   43 |   int sum = pre[y + n - 1] - pre[x - 1];
      |                     ^