Submission #931216

# Submission time Handle Problem Language Result Execution time Memory
931216 2024-02-21T11:34:50 Z LucaIlie The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 39612 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e5;
const int MAX_M = 2e5;
int n, m, d;
int h[MAX_N], a[MAX_M], b[MAX_M];
unordered_map<int, int> pos[MAX_N];
vector<int> trust[MAX_N];
set<int> hy;


void init( int N, int D, int H[] ) {
    n = N;
    d = D;
    for ( int i = 0; i < n; i++ )
        h[i] = H[i];
    for ( int i = 0; i < n; i++ )
        trust[i].push_back( i );
}

void curseChanges( int M, int A[], int B[] ) {
    m = M;
    for ( int i = 0; i < M; i++ ) {
        a[i] = A[i];
        b[i] = B[i];
    }
}

int question( int x, int y, int t ) {
    for ( int i = 0; i < n; i++ ) {
        pos[i].clear();
        trust[i].clear();
        trust[i].push_back( i );
    }
    for ( int i = 0; i < t; i++ ) {
        if ( pos[a[i]][b[i]] == 0 ) {
            pos[a[i]][b[i]] = trust[a[i]].size();
            trust[a[i]].push_back( b[i] );

            pos[b[i]][a[i]] = trust[b[i]].size();
            trust[b[i]].push_back( a[i] );
        } else {
            int p, l;

            p = pos[a[i]][b[i]], l = trust[a[i]].size() - 1;
            swap( pos[a[i]][b[i]], pos[a[i]][l] );
            swap( trust[a[i]][p], trust[a[i]][l] );
            pos[a[i]][trust[a[i]][l]] = 0;
            trust[a[i]].pop_back();

            p = pos[b[i]][a[i]], l = trust[b[i]].size() - 1;
            swap( pos[b[i]][a[i]], pos[b[i]][l] );
            swap( trust[b[i]][p], trust[b[i]][l] );
            pos[b[i]][trust[b[i]][l]] = 0;
            trust[b[i]].pop_back();
        }
    }

    hy.clear();
    for ( int i = 1; i < trust[y].size(); i++ )
        hy.insert( h[trust[y][i]] );

    int minDist = 1e9;
    for ( int i = 1; i < trust[x].size(); i++ ) {
        int hx = h[trust[x][i]];
        auto p = hy.upper_bound( hx );
        if ( p != hy.end() )
            minDist = min( minDist, *p - hx );
        if ( p != hy.begin() ) {
            p--;
            minDist = min( minDist, hx - *p );
        }
    }

    for ( int i = 0; i < t; i++ ) {
        trust[a[i]].clear();
        trust[a[i]].push_back( a[i] );
        pos[a[i]].clear();

        trust[b[i]].clear();
        trust[a[i]].push_back( b[i] );
        pos[b[i]].clear();
    }

    return minDist;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:62:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for ( int i = 1; i < trust[y].size(); i++ )
      |                      ~~^~~~~~~~~~~~~~~~~
potion.cpp:66:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for ( int i = 1; i < trust[x].size(); i++ ) {
      |                      ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 9056 KB Output is correct
2 Correct 65 ms 9060 KB Output is correct
3 Correct 73 ms 9056 KB Output is correct
4 Correct 620 ms 13536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3045 ms 39612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3003 ms 39212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 10960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 65 ms 9056 KB Output is correct
3 Correct 65 ms 9060 KB Output is correct
4 Correct 73 ms 9056 KB Output is correct
5 Correct 620 ms 13536 KB Output is correct
6 Execution timed out 3045 ms 39612 KB Time limit exceeded
7 Halted 0 ms 0 KB -