답안 #823934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823934 2023-08-13T10:29:41 Z thimote75 식물 비교 (IOI20_plants) C++14
14 / 100
4000 ms 9040 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;
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 316 KB Output is correct
7 Correct 135 ms 5016 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 135 ms 5088 KB Output is correct
11 Correct 114 ms 5028 KB Output is correct
12 Correct 109 ms 5196 KB Output is correct
13 Correct 163 ms 5016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 5 ms 316 KB Output is correct
7 Correct 135 ms 5016 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 135 ms 5088 KB Output is correct
11 Correct 114 ms 5028 KB Output is correct
12 Correct 109 ms 5196 KB Output is correct
13 Correct 163 ms 5016 KB Output is correct
14 Correct 1074 ms 5456 KB Output is correct
15 Execution timed out 4056 ms 9040 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 340 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -