답안 #301257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
301257 2020-09-17T19:06:17 Z Sorting 식물 비교 (IOI20_plants) C++17
0 / 100
1 ms 256 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

vector<array<int, 2>> range;

bool make_changes(int k, int n, vector<int> &r){
    bool ans = false;
    for(int i = 0; i < n; ++i){
        int j = (i + 1) % n;
        int b = r[i], sm = k - 1 - r[i];

        vector<int> v[2]; 
        for(int _ = 0; _ < k - 1; ++_){
            v[0].push_back(range[j][0]);
            v[1].push_back(range[j][1]);

            j++;
            if(j == n) j = 0;
        }

        sort(v[0].begin(), v[0].end());
        sort(v[1].begin(), v[1].end());

        array<int, 2> curr_range = range[i];
        range[i] = {0, n - 1};

        for(int j = sm; j < k - 1; ++j)
            range[i][1] = min(range[i][1], v[1][j] - (j - sm + 1));
        for(int j = sm - 1; j >= 0; --j)
            range[i][0] = max(range[i][0], v[0][j] + (sm - j));

        //cout << range[i][0] << "," << range[i][1] << " " << curr_range[0] << "," << curr_range[1] << endl;

        if(range[i] != curr_range)
            ans = true;
    }

    return ans;
}

void init(int k, vector<int> r) {
	int n = r.size();
    range.resize(n, {0, n - 1});

    while(make_changes(k, n, r));
}

int compare_plants(int x, int y) {
	if(range[x][1] <= range[y][0]) return -1;
    if(range[x][0] >= range[y][1]) return 1;
    return 0;
}

/*
4 3 2
0 1 1 2
0 2
1 2
*/

Compilation message

plants.cpp: In function 'bool make_changes(int, int, std::vector<int>&)':
plants.cpp:12:13: warning: unused variable 'b' [-Wunused-variable]
   12 |         int b = r[i], sm = k - 1 - r[i];
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 1 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -