Submission #924756

# Submission time Handle Problem Language Result Execution time Memory
924756 2024-02-09T16:02:13 Z boris_mihov Monster Game (JOI21_monster) C++17
0 / 100
61 ms 596 KB
#include "monster.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>

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

std::mt19937 rng(69420);
std::vector <int> v;
std::vector <int> res;

void rec(int l, int r)
{
    if (l == r)
    {
        return;
    }   

    int mid = (l + r) / 2;
    rec(l, mid);
    rec(mid + 1, r);

    int ptr = l;
    int lPtr = l, rPtr = mid + 1;
    while (lPtr <= mid || rPtr <= r)
    {
        if (lPtr == mid + 1)
        {
            res[ptr++] = v[rPtr++];
            continue;
        }

        if (rPtr == r + 1)
        {
            res[ptr++] = v[lPtr++];
            continue;
        }

        if (Query(v[rPtr], v[lPtr]))
        {
            res[ptr++] = v[lPtr++];
        } else
        {
            res[ptr++] = v[rPtr++];
        }
    }

    for (int i = l ; i <= r ; ++i)
    {
        v[i] = res[i];
    }
}

int cnt[10];
std::vector <int> Solve(int n) 
{
    v.resize(n);
    res.resize(n);
    std::iota(v.begin(), v.end(), 0);
    std::shuffle(v.begin(), v.end(), rng);
    rec(0, n - 1);

    for (int i = 0 ; i < std::min(10, n) ; ++i)
    {
        for (int j = i + 1 ; j < std::min(10, n) ; ++j)
        {
            if (Query(v[i], v[j])) cnt[i]++;
            else cnt[j]++;
        }
    }

    int min = 0;
    for (int i = 1 ; i < std::min(10, n) ; ++i)
    {
        if (cnt[i] == 1)
        {
            min = i;
        }
    }

    std::swap(v[0], v[min]);

    int idx = 0;
    for (int i = 1 ; i < n ; ++i)
    {
        if (Query(v[idx], v[i]))
        {
            std::reverse(v.begin() + idx + 1, v.begin() + i + 1);
            idx = i;
        }
    }
    
    for (int i = 0 ; i < n ; ++i)
    {
        res[v[i]] = i;
    }

    return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 424 KB Output is correct
2 Correct 45 ms 504 KB Output is correct
3 Correct 51 ms 420 KB Output is correct
4 Correct 41 ms 596 KB Output is correct
5 Correct 43 ms 424 KB Output is correct
6 Correct 41 ms 592 KB Output is correct
7 Correct 49 ms 344 KB Output is correct
8 Correct 61 ms 424 KB Output is correct
9 Incorrect 50 ms 420 KB Wrong Answer [3]
10 Halted 0 ms 0 KB -