답안 #849191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849191 2023-09-14T09:03:13 Z faruk The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 100372 KB
#include <bits/stdc++.h>    	
#define all(a) a.begin(), a.end()

using namespace std;

typedef pair<int, int> pii;

const int C = 50;

struct checkpoint {
    int time;
    set<int> guys;

    checkpoint() {}
    checkpoint(int T, set<int> sett) {
        time = T;
        guys = sett;
    }
    bool operator<(const checkpoint &a) const {return time < a.time;}
};

int n, d, u;
vector<int> heights;
vector<pii> changes;

int min_dist(vector<int> first, vector<int> second) {
    if (first.empty() || second.empty())
        return 1e9;
    for (int i = 0; i < first.size(); i++)
        first[i] = heights[first[i]];
    for (int i = 0; i <second.size(); i++)
        second[i] = heights[second[i]];
    sort(all(first));
    sort(all(second));

    int pnt1 = 0, pnt2 = 0, out = 2e9;
    while (pnt1 < first.size() and pnt2 < second.size()) {
        out = min(out, abs(first[pnt1] - second[pnt2]));

        if (pnt1 + 1 == first.size())
            pnt2++;
        else if (pnt2 + 1 == second.size())
            pnt1++;
        else if (first[pnt1] < second[pnt2])
            pnt1++;
        else
            pnt2++;
    }
    return out;
}

vector<vector<checkpoint> > states;
vector<vector<pii> > individ_updates;
void init(int N, int D, int H[]) {
    n = N;
    individ_updates.resize(n);
    states.resize(n);
    heights.resize(N);
    for (int i = 0; i < n; i++)
    {
        heights[i] = H[i];
        states[i].push_back(checkpoint(-1, set<int>()));
    }
    d = D;
    states.resize(n);
}

void process(set<int> &set, int &val) {
    if (set.count(val))
        set.erase(val);
    else
        set.insert(val);
}

void curseChanges(int U, int A[], int B[]) {
    u = U;
    changes.resize(u);
    for (int i = 0; i < u; i++)
    {
        changes[i].first = A[i], changes[i].second = B[i];
        individ_updates[A[i]].push_back({i, B[i]});
        individ_updates[B[i]].push_back({i, A[i]});
    }
    
    vector<int> time_since_last(n, 0);
    vector<set<int> > guys(n);
    for (int i = 0; i < u; i++) {
        int a = changes[i].first, b = changes[i].second;
        process(guys[a], b);
        process(guys[b], a);
        if (time_since_last[a] == C) {
            states[a].push_back(checkpoint(i, guys[a]));
            time_since_last[a] = 0;
        }
        if (time_since_last[b] == C) {
            states[b].push_back(checkpoint(i, guys[b]));
            time_since_last[b] = 0;
        }
        time_since_last[a]++;
        time_since_last[b]++;
    }
}

// todo; finish get set
set<int> get_set(int x, int v) {
    checkpoint check = *prev(upper_bound(all(states[x]), checkpoint(v, set<int>())));
    int idx = lower_bound(all(individ_updates[x]), pii(check.time, 1e9)) - individ_updates[x].begin();
    for (; idx < individ_updates[x].size() and individ_updates[x][idx].first < v; idx++)
        process(check.guys, individ_updates[x][idx].second);
    return check.guys;
}

int question(int x, int y, int v) {
    set<int> x_set = get_set(x, v), y_set = get_set(y, v);
    
    return min_dist(vector<int>(x_set.begin(), x_set.end()), vector<int>(y_set.begin(), y_set.end()));
}

Compilation message

potion.cpp: In function 'int min_dist(std::vector<int>, std::vector<int>)':
potion.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = 0; i < first.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
potion.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i <second.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
potion.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (pnt1 < first.size() and pnt2 < second.size()) {
      |            ~~~~~^~~~~~~~~~~~~~
potion.cpp:37:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (pnt1 < first.size() and pnt2 < second.size()) {
      |                                    ~~~~~^~~~~~~~~~~~~~~
potion.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if (pnt1 + 1 == first.size())
      |             ~~~~~~~~~^~~~~~~~~~~~~~~
potion.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         else if (pnt2 + 1 == second.size())
      |                  ~~~~~~~~~^~~~~~~~~~~~~~~~
potion.cpp: In function 'std::set<int> get_set(int, int)':
potion.cpp:108:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for (; idx < individ_updates[x].size() and individ_updates[x][idx].first < v; idx++)
      |            ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 21 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 45196 KB Output is correct
2 Correct 260 ms 45024 KB Output is correct
3 Correct 326 ms 28380 KB Output is correct
4 Execution timed out 3013 ms 64756 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 267 ms 45160 KB Output is correct
2 Execution timed out 3023 ms 100372 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3672 KB Output is correct
2 Correct 189 ms 2680 KB Output is correct
3 Incorrect 33 ms 2680 KB Incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 21 ms 17876 KB Output is correct
6 Correct 284 ms 45196 KB Output is correct
7 Correct 260 ms 45024 KB Output is correct
8 Correct 326 ms 28380 KB Output is correct
9 Execution timed out 3013 ms 64756 KB Time limit exceeded
10 Halted 0 ms 0 KB -