답안 #701865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701865 2023-02-22T08:20:17 Z Darren0724 The Potion of Great Power (CEOI20_potion) C++17
38 / 100
3000 ms 51204 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].back().second==0){
            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:56:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     while(ptr1<a.size()&&ptr2<b.size()){
      |           ~~~~^~~~~~~~~
potion.cpp:56:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     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 592 KB Output is correct
4 Correct 14 ms 6032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 51192 KB Output is correct
2 Correct 337 ms 51096 KB Output is correct
3 Correct 657 ms 11820 KB Output is correct
4 Execution timed out 3045 ms 32428 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 51204 KB Output is correct
2 Execution timed out 3056 ms 20288 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3152 KB Output is correct
2 Correct 197 ms 1892 KB Output is correct
3 Correct 352 ms 1360 KB Output is correct
4 Correct 2029 ms 2384 KB Output is correct
5 Correct 1835 ms 2896 KB Output is correct
6 Correct 173 ms 2512 KB Output is correct
7 Correct 1981 ms 1500 KB Output is correct
# 결과 실행 시간 메모리 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 592 KB Output is correct
5 Correct 14 ms 6032 KB Output is correct
6 Correct 323 ms 51192 KB Output is correct
7 Correct 337 ms 51096 KB Output is correct
8 Correct 657 ms 11820 KB Output is correct
9 Execution timed out 3045 ms 32428 KB Time limit exceeded
10 Halted 0 ms 0 KB -