結果

問題 No.1244 Black Segment
ユーザー auaua
提出日時 2020-10-02 22:14:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 179,196 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-07-17 21:28:37
合計ジャッジ時間 4,900 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF;
const ll MOD=998244353;
const ll mod=MOD;
const int MAX=200010;

signed main(){
    ll n,m,a,b;cin>>n>>m>>a>>b;
    vector<pll>p(m);
    vector<pll>q(m);
    rep(i,m){
        cin>>p[i].fi>>p[i].se;
        q[i].se=p[i].fi,q[i].fi=p[i].se;
    }
    sort(all(p));
    sort(rall(q));
    vector<ll>dp(n+2,0);
    REP(i,a,n+2)dp[i]=inf;
    rep(i,m){
        dp[p[i].se]=min(dp[p[i].se],dp[p[i].fi-1]+1);
    }
    rep(i,m){
        dp[q[i].se-1]=min(dp[q[i].se-1],dp[q[i].fi]+1);
    }
    rep(i,m){
        dp[p[i].se]=min(dp[p[i].se],dp[p[i].fi-1]+1);
    }
    ll ans=inf;
    REP(i,b,n+2)ans=min(ans,dp[i]);
    if(ans==inf){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
}
0