Submission #434588

# Submission time Handle Problem Language Result Execution time Memory
434588 2021-06-21T12:28:24 Z pere_gil Comparing Plants (IOI20_plants) C++17
5 / 100
120 ms 6104 KB
#include "plants.h"
#include "bits/stdc++.h"
using namespace std;

vector<int> v;
vector<int> acc;
int tam;

void init(int k, std::vector<int> r) {
	v=r;
	tam=k;

	acc.push_back(v[0]);
	for(int i=1;i<v.size();i++)
		acc.push_back(acc[i-1]+v[i]);
	
	return;
}

bool op1(int l, int r){
	int aux;
	if(l<r){
		aux=acc[r-1];
		aux-=(l==0) ? 0 : acc[l-1];
		return aux==(r-l);
	}

	aux=acc.back()-acc[l-1];
	aux+=(r==0) ? 0 : acc[r-1];
	return aux==(acc.size()-l+r);
}

bool op2(int l, int r){
	int aux;
	if(l<r){
		aux=acc[r-1];
		aux-=(l==0) ? 0 : acc[l-1];
		return !aux;
	}

	aux=acc.back()-acc[l-1];
	aux+=(r==0) ? 0 : acc[r-1];
	return !aux;
}

int compare_plants(int x, int y) {
	if(op1(x,y) || op2(y,x)) return -1;
	if(op1(y,x) || op2(x,y)) return 1;
	return 0;
	
	return 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:14:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i=1;i<v.size();i++)
      |              ~^~~~~~~~~
plants.cpp: In function 'bool op1(int, int)':
plants.cpp:30:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  return aux==(acc.size()-l+r);
      |         ~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 62 ms 3028 KB Output is correct
7 Correct 70 ms 3472 KB Output is correct
8 Correct 93 ms 6072 KB Output is correct
9 Correct 93 ms 6104 KB Output is correct
10 Correct 93 ms 6080 KB Output is correct
11 Correct 120 ms 6076 KB Output is correct
12 Correct 93 ms 6068 KB Output is correct
13 Correct 89 ms 6072 KB Output is correct
14 Correct 86 ms 6076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 62 ms 3028 KB Output is correct
7 Correct 70 ms 3472 KB Output is correct
8 Correct 93 ms 6072 KB Output is correct
9 Correct 93 ms 6104 KB Output is correct
10 Correct 93 ms 6080 KB Output is correct
11 Correct 120 ms 6076 KB Output is correct
12 Correct 93 ms 6068 KB Output is correct
13 Correct 89 ms 6072 KB Output is correct
14 Correct 86 ms 6076 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Incorrect 1 ms 204 KB Output isn't correct
18 Halted 0 ms 0 KB -