Submission #1236047

#TimeUsernameProblemLanguageResultExecution timeMemory
1236047stanirinaComparing Plants (IOI20_plants)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "plants.h"



vector<int> v;
vector<int> rc;
int nn;
int kk;

void init(int k, std::vector<int> r) {
    kk=k;
    nn=r.size();
    rc.resize(nn*2);
    v.resize(nn,0);
    for(int i=0;i<nn;i++)rc[i]=rc[i+nn]=r[i];
    //for(int i=0;i<2*nn;i++)cout<<rc[i]<<' ';
    //cout<<endl;
    for(int i=nn;i<2*nn;i++){
        if(rc[i]==rc[i-1])v[nn-1]++;
        else break;
    }
    //cout<<v[n-1]<<endl;
    for(int i=nn-2;i>=0;i--){
        if(rc[i]==rc[i+1])v[i]=v[i+1]+1;
        else v[i]=0;
    }
    //for(int i=0;i<n;i++)cout<<v[i]<<' ';
    //cout<<endl;
	return;
}

int compare_plants(int x, int y) {
    //cout<<v[x]<<' '<<v[y]<<endl;
	if(x+v[x]>=y){
        if(rc[x]==1)return -1;
        else return 1;
	}
	if((y+v[y])>=nn && (y+v[y])%nn>=x){
        if(rc[y]==1)return 1;
        else return -1;
	}
	return 0;
}

Compilation message (stderr)

plants.cpp:6:1: error: 'vector' does not name a type
    6 | vector<int> v;
      | ^~~~~~
plants.cpp:7:1: error: 'vector' does not name a type
    7 | vector<int> rc;
      | ^~~~~~
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:14:5: error: 'rc' was not declared in this scope; did you mean 'r'?
   14 |     rc.resize(nn*2);
      |     ^~
      |     r
plants.cpp:15:5: error: 'v' was not declared in this scope
   15 |     v.resize(nn,0);
      |     ^
plants.cpp: In function 'int compare_plants(int, int)':
plants.cpp:35:14: error: 'v' was not declared in this scope
   35 |         if(x+v[x]>=y){
      |              ^
plants.cpp:36:12: error: 'rc' was not declared in this scope
   36 |         if(rc[x]==1)return -1;
      |            ^~
plants.cpp:39:15: error: 'v' was not declared in this scope
   39 |         if((y+v[y])>=nn && (y+v[y])%nn>=x){
      |               ^
plants.cpp:40:12: error: 'rc' was not declared in this scope
   40 |         if(rc[y]==1)return 1;
      |            ^~