Submission #1239083

#TimeUsernameProblemLanguageResultExecution timeMemory
1239083justThe Potion of Great Power (CEOI20_potion)C++20
0 / 100
1194 ms327680 KiB
#include "bits/stdc++.h"
using namespace std;

#define vec vector
#define all(x) (x).begin(), (x).end()

const int inf = 1e9;

using pii = pair<int, int>;

int n, d, u;
vec<int> h, a, b;


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

void curseChanges(int U, int A[], int B[]) {
    u = U;
    a.resize(U);
    b.resize(U);
    for (int i = 0; i < U; i++) a[i] = A[i], b[i] = B[i];
}

int question(int x, int y, int v) {
    set<pii> friends;
    for (int i = 0; i <= v; i++) {
        int x = a[i], y = b[i];
        if (x > y) swap(x, y);
        
        auto it = friends.find({x, y});
        if (it != friends.end()) friends.erase(it);
        else friends.insert({x, y});
    }

    // for (auto [x, y]: friends) cerr << x << ' ' << y << endl;

    vec<vec<bool>> dist(n, vec<bool>(n, false));
    for (int i = 0; i < n; i++) dist[i][i] = 1;
    for (auto [x, y]: friends) dist[x][y] = dist[y][x] = 1;

    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) cerr << (dist[i][j] ? 1 : 0) << ' ';
    //     cerr << endl;
    // }

    for (int i = 0; i < n; i++) {
        if (dist[x][i] && dist[i][y]) return 0;
    }

    int ans = inf;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++)
        if (i != x && j != y && dist[x][i] && dist[j][y]) 
            ans = min(ans, abs(h[i] - h[j]));
    
    return ans;
}

// int main() {
//     int n, d, u, q;
//     cin >> n >> d >> u >> q;

//     vec<int> h(n);
//     for (int i = 0; i < n; i++) cin >> h[i];

//     init(n, d, h.data());

//     vec<int> a(u), b(u);
//     for (int i = 0; i < u; i++) cin >> a[i] >> b[i];
//     curseChanges(u, a.data(), b.data());

//     while (q--) {
//         int x, y, v; cin >> x >> y >> v;
//         cout << question(x, y, v) << endl;
//     }

//     return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...