답안 #701859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701859 2023-02-22T08:13:54 Z Darren0724 The Potion of Great Power (CEOI20_potion) C++17
17 / 100
372 ms 51280 KB
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> h;
struct cmp{
    bool operator()(const int &a,const int &b)const{
        if(h[a]==h[b]){
            return a<b;
        }
        return h[a]<h[b];
    }
};
vector<map<int,vector<pair<int,int>>>> s;
void init(int N, int D, int H[]) {
    n=N;
    h.resize(n);
    s.resize(n);
    for(int i=0;i<n;i++){
        h[i]=H[i];
    }

}

void curseChanges(int U, int A[], int B[]) {
    for(int i=1;i<=U;i++){
        int a=A[i-1];
        int b=B[i-1];
        if(s[a].find(b)==s[a].end()){
            s[a][b].push_back({i,1});
            s[b][a].push_back({i,1});
        }
        else{
            s[a][b].push_back({i,0});
            s[b][a].push_back({i,0});
        }
    }
}

int question(int x, int y, int v) {
    int ans=1000000000;
    vector<int> a,b;
    for(pair<int,vector<pair<int,int>>> j:s[x]){
        int tmp=(--upper_bound(j.second.begin(),j.second.end(),make_pair(v,10)))->second;
        if(tmp==1){
            a.push_back(j.first);
        }
    }
    for(pair<int,vector<pair<int,int>>> j:s[y]){
        int tmp=(--upper_bound(j.second.begin(),j.second.end(),make_pair(v,10)))->second;
        if(tmp==1){
            b.push_back(j.first);
        }
    }
    sort(a.begin(),a.end(),cmp());
    sort(b.begin(),b.end(),cmp());
    int ptr1=0,ptr2=0;
    while(ptr1<a.size()&&ptr2<b.size()){
        int a1=a[ptr1];
        int b1=b[ptr2];
        ans=min(ans,abs(h[a1]-h[b1]));
        if(h[a1]<h[b1]){
            ptr1++;
        }
        else{
            ptr2++;
        }
    }

    return ans;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     while(ptr1<a.size()&&ptr2<b.size()){
      |           ~~~~^~~~~~~~~
potion.cpp:57:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     while(ptr1<a.size()&&ptr2<b.size()){
      |                          ~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 15 ms 5976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 51280 KB Output is correct
2 Correct 354 ms 51200 KB Output is correct
3 Incorrect 71 ms 11780 KB Incorrect
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 51196 KB Output is correct
2 Incorrect 159 ms 20336 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3040 KB Output is correct
2 Incorrect 7 ms 1916 KB Incorrect
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 15 ms 5976 KB Output is correct
6 Correct 372 ms 51280 KB Output is correct
7 Correct 354 ms 51200 KB Output is correct
8 Incorrect 71 ms 11780 KB Incorrect
9 Halted 0 ms 0 KB -