답안 #724851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
724851 2023-04-16T05:33:57 Z guagua0407 Exhibition (JOI19_ho_t2) C++17
0 / 100
2 ms 2644 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=1e5+5;
pair<int,int> num[mxn];
int C[mxn];
int pos[mxn];
vector<int> vals[mxn];
int n,m;

bool check(int mid){
    priority_queue<int,vector<int>,greater<int>> pq;
    for(int i=1;i<mid;i++){
        for(auto v:vals[i]){
            pq.push(v);
        }
    }
    int cur=-1;
    for(int i=mid;i<=m;i++){
        for(auto v:vals[i]){
            pq.push(v);
        }
        if(pq.empty()) return false;
        int v=pq.top();
        pq.pop();
        if(v<cur) return false;
        cur=v;
    }
    return true;
}

int main() {_
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>num[i].f>>num[i].s;
    }
    for(int i=1;i<=m;i++){
        cin>>C[i];
    }
    sort(C+1,C+m+1);
    for(int i=1;i<=n;i++){
        pos[i]=lower_bound(C+1,C+m+1,num[i].f)-C;
        vals[pos[i]].push_back(num[i].s);
    }
    int l=1,r=m+1;
    while(l<r){
        int mid=(l+r)/2;
        if(check(mid)){
            r=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<m+1-l;
    return 0;
}
//maybe its multiset not set

Compilation message

joi2019_ho_t2.cpp: In function 'void setIO(std::string)':
joi2019_ho_t2.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t2.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Incorrect 2 ms 2644 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Incorrect 2 ms 2644 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Incorrect 2 ms 2644 KB Output isn't correct
6 Halted 0 ms 0 KB -