Submission #823937

# Submission time Handle Problem Language Result Execution time Memory
823937 2023-08-13T10:31:46 Z thimote75 Comparing Plants (IOI20_plants) C++14
14 / 100
4000 ms 5352 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

using idata = vector<int>;

void shift (idata &r, int count) {
	idata h;
	for (int i = count; i < r.size(); i ++)
		h.push_back(r[i]);
	for (int i = 0; i < count; i ++)
		h.push_back(r[i]);
	
	r.swap(h);
}

idata A;

void init(int k, idata r) {
	int n = r.size();
	//assert(n < 2 * k);

	vector<int> null_points;
	for (int i = 0; i < n; i ++) {
		if (r[i] == 0) {
			r[i] = -1;
			null_points.push_back(i);
			null_points.push_back(i + n);
		}
	}

	int p0 = 0;
	sort(null_points.begin(), null_points.end());
	
	for (int i = 1; i * 2 < null_points.size(); i ++) {
		int del = null_points[i] - null_points[i - 1];
		if (del < k) continue ;

		p0 = i;
		break ;
	}

	p0 = null_points[p0 + (null_points.size() >> 1) - 1] % n;

	shift(r, p0 + 1);

	A.resize(n);

	int s = 0;

	for (int v = n - 1; v >= 0; v --) {
		int p = 0; int m = 1e9;

		for (int i = 0; i < n; i ++) {
			if (r[i] > m) continue ;
			if (r[i] == m) {
				int d = n + p - i;
				if (d >= k) continue ;
			}
		
			p = i;
			m = r[i];
		}

		r[p] = 1e9;
		for (int g = p - 1; g > p - k; g --) r[(g + n) % n] --;
	
		A[(p + p0 + 1) % n] = v;
	}

	return;
}

int compare_plants(int x, int y) {
	int del = A[x] - A[y];
	if (del == 0) return 0;
	return del / abs(del);
}

Compilation message

plants.cpp: In function 'void shift(idata&, int)':
plants.cpp:10:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = count; i < r.size(); i ++)
      |                      ~~^~~~~~~~~~
plants.cpp: In function 'void init(int, idata)':
plants.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 1; i * 2 < null_points.size(); i ++) {
      |                  ~~~~~~^~~~~~~~~~~~~~~~~~~~
plants.cpp:50:6: warning: unused variable 's' [-Wunused-variable]
   50 |  int s = 0;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 140 ms 3120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 150 ms 3172 KB Output is correct
11 Correct 115 ms 3148 KB Output is correct
12 Correct 129 ms 3316 KB Output is correct
13 Correct 162 ms 3120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 5 ms 340 KB Output is correct
7 Correct 140 ms 3120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 6 ms 340 KB Output is correct
10 Correct 150 ms 3172 KB Output is correct
11 Correct 115 ms 3148 KB Output is correct
12 Correct 129 ms 3316 KB Output is correct
13 Correct 162 ms 3120 KB Output is correct
14 Correct 1183 ms 3236 KB Output is correct
15 Execution timed out 4061 ms 5352 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 45 ms 4828 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -