Submission #359950

# Submission time Handle Problem Language Result Execution time Memory
359950 2021-01-27T11:10:11 Z Sorting Comparing Plants (IOI20_plants) C++17
5 / 100
97 ms 7276 KB
#include "plants.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;

int r[N], cnt[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];

    cnt[0] = 1;
    for(int i = 1; i < n; ++i)
        cnt[i] = (r[i] == r[i - 1]) ? cnt[i - 1] + 1 : 1;

    if(r[0] == r[n - 1] && cnt[n - 1] != n){
        int i = 0;
        while(r[i] == r[0]){
            cnt[i] += cnt[n - 1];
            i++;
        }
    }
}

int compare_plants(int x, int y) {
    if(cnt[y - 1] >= y - x) return r[x] ? -1 : 1;
    if(cnt[(x - 1 + n) % n] >= x + n - y) return r[y] ? 1 : -1;
    return 0; 
}

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)
      |                    ~~^~~~~~~~~~~
# 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 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 60 ms 4076 KB Output is correct
7 Correct 83 ms 4864 KB Output is correct
8 Correct 97 ms 7228 KB Output is correct
9 Correct 91 ms 7148 KB Output is correct
10 Correct 93 ms 7276 KB Output is correct
11 Correct 95 ms 7076 KB Output is correct
12 Correct 88 ms 7148 KB Output is correct
13 Correct 85 ms 7148 KB Output is correct
14 Correct 89 ms 7148 KB Output is correct
# 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 Incorrect 1 ms 364 KB Output isn't correct
3 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 -
# 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 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 60 ms 4076 KB Output is correct
7 Correct 83 ms 4864 KB Output is correct
8 Correct 97 ms 7228 KB Output is correct
9 Correct 91 ms 7148 KB Output is correct
10 Correct 93 ms 7276 KB Output is correct
11 Correct 95 ms 7076 KB Output is correct
12 Correct 88 ms 7148 KB Output is correct
13 Correct 85 ms 7148 KB Output is correct
14 Correct 89 ms 7148 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Incorrect 1 ms 364 KB Output isn't correct
18 Halted 0 ms 0 KB -