Submission #434462

# Submission time Handle Problem Language Result Execution time Memory
434462 2021-06-21T10:37:01 Z rqi Comparing Plants (IOI20_plants) C++17
5 / 100
115 ms 10200 KB
#include "plants.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;

#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()

const int mx = 200005;
pi rangs[mx][2];

void init(int k, vi r) {
	int n = sz(r);

	int start = 0;
	for(int i = 0; i < n; i++){
		if(r[i] != r[0]){
			start = i;
			break;
		}
	}

	int cur = start;

	while(true){
		int end_ind = cur;
		while(r[(end_ind+1) % n] == r[cur]){
			end_ind = (end_ind+1) % n;
		}

		pi interval = mp(cur, (end_ind+1) % n);

		// cout << cur << " " << end_ind << "\n";
		// cout << interval.f << " " << interval.s << "\n";
		for(int i = cur; ; (i = (i+1) % n)){
			if(i == cur){
				rangs[i][1] = mp(r[cur], interval.s);
			}
			else if(i == (end_ind+1) % n){
				rangs[i][0] = mp(r[cur], interval.f);
				break;
			}
			else{
				rangs[i][0] = mp(r[cur], interval.f);
				rangs[i][1] = mp(r[cur], interval.s);
			}
		}

		cur = (end_ind+1) % n;
		if(cur == start) break;
	}

	return;
}

bool isInInterval(int test, int int_beg, int int_end){
	if(int_beg <= int_end){
		return (int_beg <= test) && (test <= int_end);
	}

	return (int_beg <= test) || (test <= int_end);
}

int compare_plants(int x, int y) {
	if(isInInterval(y, rangs[x][0].s, x)){
		if(rangs[x][0].f == 1){
			return 1;
		}
		else{
			return -1;
		}
	}
	else if(isInInterval(y, x, rangs[x][1].s)){
		if(rangs[x][1].f == 1){
			return -1;
		}
		else{
			return 1;
		}
	}
	return 0;
}
# 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 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 58 ms 4036 KB Output is correct
7 Correct 78 ms 5744 KB Output is correct
8 Correct 99 ms 10160 KB Output is correct
9 Correct 93 ms 10176 KB Output is correct
10 Correct 93 ms 10200 KB Output is correct
11 Correct 104 ms 10184 KB Output is correct
12 Correct 93 ms 10192 KB Output is correct
13 Correct 115 ms 10200 KB Output is correct
14 Correct 97 ms 10200 KB Output is correct
# 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 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 1 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 1 ms 204 KB Output is correct
3 Correct 1 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 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 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 1 ms 204 KB Output is correct
2 Correct 0 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 58 ms 4036 KB Output is correct
7 Correct 78 ms 5744 KB Output is correct
8 Correct 99 ms 10160 KB Output is correct
9 Correct 93 ms 10176 KB Output is correct
10 Correct 93 ms 10200 KB Output is correct
11 Correct 104 ms 10184 KB Output is correct
12 Correct 93 ms 10192 KB Output is correct
13 Correct 115 ms 10200 KB Output is correct
14 Correct 97 ms 10200 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Incorrect 1 ms 204 KB Output isn't correct
18 Halted 0 ms 0 KB -