Submission #823917

# Submission time Handle Problem Language Result Execution time Memory
823917 2023-08-13T10:08:18 Z thimote75 Comparing Plants (IOI20_plants) C++14
0 / 100
1 ms 340 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] == 0) {
			r[i] = -1;
			p0 = i;
		}
	}
	
	shift(r, p0 + 1);

	A.resize(n);

	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 ;
		
			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;
	}
	for (int u : A) cout << u << " "; cout << endl;

	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:51:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   51 |  for (int u : A) cout << u << " "; cout << endl;
      |  ^~~
plants.cpp:51:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   51 |  for (int u : A) cout << u << " "; cout << endl;
      |                                    ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 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 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -