Submission #823909

# Submission time Handle Problem Language Result Execution time Memory
823909 2023-08-13T09:59:27 Z thimote75 Comparing Plants (IOI20_plants) C++14
0 / 100
1 ms 468 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);

	int p0 = - 1;
	for (int i = 0; i < n; i ++) {
		if (r[i] == k - 1) {
			assert(p0 == -1);
			p0 = i;
		}
	}
	
	shift(r, p0 + 1);

	A.resize(n);

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

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

		r[p] = -1e9;
		for (int g = p - 1; g >= 0 && g > p - k; g --) r[g] ++;
	
		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 ++)
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 340 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -