답안 #827985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827985 2023-08-17T00:40:12 Z boyliguanhan The Potion of Great Power (CEOI20_potion) C++17
56 / 100
3000 ms 173940 KB
#include<bits/stdc++.h>
//#include "potion.h"
#pragma GCC optimize(2)
#define NN 100100
using namespace std;
int h[NN], n;
map<int, vector<int>> adj[NN];
void init(int N, int D, int H[]) {
    n = N;
    for(int i = 0; i < N; i++)
        h[i] = H[i];
}
set<int> arr[100100];
map<int, int> mp[100100];
void curseChanges(int U, int A[], int B[]) {
    for(int i = 0; i < n; i++) adj[i][0];
    for(int i = 1; i <= U; i++) {
        int a = A[i-1], b = B[i-1];
        set<int> &x = arr[a], &y = arr[b];
        if(x.count(b)) x.erase(b), mp[a][h[b]]--, y.erase(a), mp[b][h[a]]--;
        else x.insert(b), y.insert(a), mp[a][h[b]]++, mp[b][h[a]]++;
        vector<int> x1, y1;
        for(auto j: mp[a]) if(j.second)x1.push_back(j.first);
        for(auto j: mp[b]) if(j.second)y1.push_back(j.first);
        sort(x1.begin(),x1.end());
        sort(y1.begin(), y1.end());
        adj[a][i] = x1, adj[b][i] = y1;
    }
}
int calc(vector<int> a, vector<int> b){
    int ans = 1e9;
    for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
        if(a[i]>b[j]) swap(a, b), swap(i, j);
        if(j) ans=min(ans,abs(a[i]-b[j-1]));
        ans = min(ans, abs(a[i] - b[j]));
    }
    return ans;
}
int question(int x, int y, int v) {
    vector<int> a = (--adj[x].upper_bound(v))->second, b = (--adj[y].upper_bound(v))->second;
    vector<int> c, d;
    for(auto i: a) c.push_back(i);
    for(auto i: b) d.push_back(i);
    return calc(c,d);
}

Compilation message

potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:32:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
      |                           ~~^~~~~~~~~~
potion.cpp:32:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0, j = 0; i < a.size()&&j < b.size();i++) {
      |                                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14848 KB Output is correct
2 Correct 9 ms 14800 KB Output is correct
3 Correct 10 ms 14800 KB Output is correct
4 Correct 23 ms 23368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 106220 KB Output is correct
2 Correct 661 ms 106308 KB Output is correct
3 Correct 605 ms 76284 KB Output is correct
4 Execution timed out 3036 ms 173940 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 95312 KB Output is correct
2 Correct 338 ms 68580 KB Output is correct
3 Correct 558 ms 76096 KB Output is correct
4 Correct 558 ms 76024 KB Output is correct
5 Correct 562 ms 94628 KB Output is correct
6 Correct 539 ms 76032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 19412 KB Output is correct
2 Correct 69 ms 18304 KB Output is correct
3 Correct 74 ms 18116 KB Output is correct
4 Correct 204 ms 23632 KB Output is correct
5 Correct 174 ms 22976 KB Output is correct
6 Correct 83 ms 19056 KB Output is correct
7 Correct 168 ms 21944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 9 ms 14848 KB Output is correct
3 Correct 9 ms 14800 KB Output is correct
4 Correct 10 ms 14800 KB Output is correct
5 Correct 23 ms 23368 KB Output is correct
6 Correct 665 ms 106220 KB Output is correct
7 Correct 661 ms 106308 KB Output is correct
8 Correct 605 ms 76284 KB Output is correct
9 Execution timed out 3036 ms 173940 KB Time limit exceeded
10 Halted 0 ms 0 KB -