Submission #781874

# Submission time Handle Problem Language Result Execution time Memory
781874 2023-07-13T12:22:30 Z boris_mihov Comparing Plants (IOI20_plants) C++17
14 / 100
4000 ms 9700 KB
#include "plants.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF  = 1e9;

int n, k;
int p[MAXN];
int r[MAXN];
bool guessed[MAXN];

int getPrev(int idx)
{
    if (idx == 1) return n;
    return idx - 1;
}

void init(int K, std::vector <int> R) 
{
    k = K;
    n = R.size();
    for (int i = 1 ; i <= n ; ++i)
    {
        r[i] = R[i - 1];
    }

    r[0] = -1;
    for (int currTry = 1 ; currTry <= n ; ++currTry)
    {
        std::vector <int> max;
        for (int i = 1 ; i <= n ; ++i)
        {
            if (guessed[i])
            {
                continue;
            }

            if (r[i] == k - 1)
            {
                max.push_back(i);
            }
        }

        assert(max.size());
        int pos = max[0];
        if (max.back() >= pos + k)
        {
            for (const int &j : max)
            {
                if (pos + k <= j)
                {
                    pos = j;
                    break;
                }
            }
        }

        guessed[pos] = true;
        p[pos] = currTry;
        int idx = getPrev(pos);
        for (int i = 1 ; i < k ; ++i)
        {
            r[idx]++;
            idx = getPrev(idx);
        }
    }

	return;
}

int compare_plants(int x, int y)
{
    x++;
    y++;
	if (p[x] < p[y]) return -1;
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 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 448 KB Output is correct
7 Correct 135 ms 5032 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 128 ms 5028 KB Output is correct
11 Correct 113 ms 5136 KB Output is correct
12 Correct 115 ms 5172 KB Output is correct
13 Correct 146 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 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 448 KB Output is correct
7 Correct 135 ms 5032 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 128 ms 5028 KB Output is correct
11 Correct 113 ms 5136 KB Output is correct
12 Correct 115 ms 5172 KB Output is correct
13 Correct 146 ms 5024 KB Output is correct
14 Correct 1861 ms 5612 KB Output is correct
15 Execution timed out 4040 ms 9700 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 36 ms 7020 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -