답안 #1043052

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043052 2024-08-03T19:52:27 Z beaconmc The Potion of Great Power (CEOI20_potion) C++14
0 / 100
3000 ms 150608 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
 
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;


vector<unordered_set<ll>> edges[101];
vector<ll> h;
vector<ll> a;
vector<ll> b;

void init(int N, int D, int H[]) {
    FOR(i,0,N) h.push_back(H[i]);
}

void curseChanges(int U, int A[], int B[]) {
    vector<unordered_set<ll>> tempedges(10001);
    FOR(i,0,U){
        if (i%100==0) edges[i/100] = tempedges;
        a.push_back(A[i]);
        b.push_back(B[i]);
        if (tempedges[A[i]].count(B[i])) tempedges[A[i]].erase(B[i]);
        else tempedges[A[i]].insert(B[i]);

        if (tempedges[B[i]].count(A[i])) tempedges[B[i]].erase(A[i]);
        else tempedges[B[i]].insert(A[i]);
        
    }
}

int mindiff(vector<ll>&a, vector<ll>&b){
    ll ans = 1000000000;
    vector<vector<ll>> A,B;
    for (auto&i : a) A.push_back({h[i], i});
    for (auto&i : b) B.push_back({h[i], i});

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    ll l=0,r=0;
    while (l<A.size() && r<B.size()){
        ans = min(ans, abs(A[l][0] - B[r][0]));
        if (A[l][0] < B[r][0]) l++;
        else r++;
    }
    return ans;
}

int question(int x, int y, int v) {

    vector<unordered_set<ll>> tempedges;
    tempedges = edges[v/100];

    FOR(i,(v/100)*100, v){
        if (tempedges[a[i]].count(b[i])) tempedges[a[i]].erase(b[i]);
        else tempedges[a[i]].insert(b[i]);

        if (tempedges[b[i]].count(a[i])) tempedges[b[i]].erase(a[i]);
        else tempedges[b[i]].insert(a[i]);
    }
    vector<ll> X,Y;
    for (auto&i : tempedges[x]) X.push_back(i);

    for (auto&i : tempedges[y]) Y.push_back(i);


    return mindiff(X,Y);
}

Compilation message

potion.cpp: In function 'int mindiff(std::vector<long long int>&, std::vector<long long int>&)':
potion.cpp:46:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     while (l<A.size() && r<B.size()){
      |            ~^~~~~~~~~
potion.cpp:46:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     while (l<A.size() && r<B.size()){
      |                          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 14964 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 8540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 25 ms 8512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3028 ms 150608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Runtime error 43 ms 14964 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -