Submission #359958

# Submission time Handle Problem Language Result Execution time Memory
359958 2021-01-27T11:20:21 Z Sorting Comparing Plants (IOI20_plants) C++17
0 / 100
65 ms 4984 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int r[N], p[N], k, n;

void init(int _k, vector<int> _r) {
	k = _k;
    n = _r.size();
    for(int i = 0; i < _r.size(); ++i)
        r[i] = _r[i];

    for(int i = n - 1; i >= 0; --i){
        int prev = n, idx;
        bool ok = false;
        for(int j = n - 1; j >= 0; --j){
            if(prev - j >= k && prev != n){
                idx = prev;
                ok = true;
                break;
            }
            if(!r[j]) prev = j;
        }

        if(!ok){
            for(int j = n - 1; j >= 0; --j)
                if(!r[j]){
                    idx = j;
                    break;
                }
        }

        p[idx] = i;
        r[idx] = n;
        for(int j = 1; j <= k - 1; ++j)
            r[(idx - j + n) % n]--;
    }
}

int compare_plants(int x, int y) {
    return (p[x] > p[y]) ? 1 : -1;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < _r.size(); ++i)
      |                    ~~^~~~~~~~~~~
plants.cpp:17:23: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   17 |         int prev = n, idx;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 65 ms 4984 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -