제출 #1247931

#제출 시각아이디문제언어결과실행 시간메모리
1247931hainam2k9Fire (BOI24_fire)C++20
0 / 100
92 ms10240 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,m,dp[MAXN],pre[MAXN];
vector<pair<pair<int,int>,int>> seg;
void compress(){
    vector<int> v;
    for(pair<pair<int,int>,int>& p : seg)
        v.pb(p.fi.fi), v.pb(p.fi.se);
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    if(v[0]!=0||v.back()!=m) cout << -1, exit(0);
    for(pair<pair<int,int>,int>& p : seg)
        p.fi.fi=lb(v.begin(),v.end(),p.fi.fi)-v.begin(),
        p.fi.se=lb(v.begin(),v.end(),p.fi.se)-v.begin();
    m=sz(v)-1;
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> m;
    for(int i = 1; i<=n; ++i){
        int l,r;
        cin >> l >> r;
        if(l>r) seg.pb(mp(0,r),0), seg.pb(mp(l,m),0);
        else seg.pb(mp(l,r),1);
    }
    compress();
    memset(dp,0x3f,sizeof(dp));
    for(pair<pair<int,int>,int>& p : seg){
        if(p.fi.fi==0) dp[p.fi.se]=min(dp[p.fi.se],p.se);
        pre[p.fi.fi]=max(pre[p.fi.fi],p.fi.se);
    }
    for(int i = 0; i<=m; ++i){
        if(i>0) pre[i]=max(pre[i],pre[i-1]);
        dp[pre[i]]=min(dp[pre[i]],dp[i]+1);
    }
    if(dp[m]>n) cout << -1;
    else cout << dp[m];
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:45: note: in expansion of macro 'fo'
   39 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...