結果

問題 No.1995 CHIKA Road
ユーザー 👑 kmjpkmjp
提出日時 2022-07-01 21:31:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 208,528 KB
実行使用メモリ 18,980 KB
最終ジャッジ日時 2024-05-04 15:41:44
合計ジャッジ時間 4,660 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
14,660 KB
testcase_01 AC 4 ms
14,364 KB
testcase_02 AC 4 ms
14,552 KB
testcase_03 AC 4 ms
15,088 KB
testcase_04 AC 4 ms
14,232 KB
testcase_05 AC 3 ms
14,304 KB
testcase_06 AC 8 ms
14,544 KB
testcase_07 AC 20 ms
16,424 KB
testcase_08 AC 4 ms
14,552 KB
testcase_09 AC 4 ms
15,572 KB
testcase_10 AC 40 ms
16,488 KB
testcase_11 AC 80 ms
18,980 KB
testcase_12 AC 60 ms
17,176 KB
testcase_13 AC 29 ms
15,684 KB
testcase_14 AC 28 ms
17,028 KB
testcase_15 AC 69 ms
18,192 KB
testcase_16 AC 13 ms
15,352 KB
testcase_17 AC 39 ms
17,124 KB
testcase_18 AC 66 ms
18,600 KB
testcase_19 AC 68 ms
18,708 KB
testcase_20 AC 37 ms
16,212 KB
testcase_21 AC 35 ms
16,988 KB
testcase_22 AC 63 ms
18,012 KB
testcase_23 AC 22 ms
15,256 KB
testcase_24 AC 56 ms
17,628 KB
testcase_25 AC 14 ms
15,496 KB
testcase_26 AC 26 ms
16,124 KB
testcase_27 AC 56 ms
17,652 KB
testcase_28 AC 35 ms
16,588 KB
testcase_29 AC 67 ms
18,404 KB
testcase_30 AC 14 ms
15,616 KB
testcase_31 AC 9 ms
14,868 KB
testcase_32 AC 17 ms
15,044 KB
testcase_33 AC 52 ms
18,084 KB
testcase_34 AC 9 ms
14,920 KB
testcase_35 AC 21 ms
15,336 KB
testcase_36 AC 25 ms
16,548 KB
testcase_37 AC 58 ms
18,856 KB
testcase_38 AC 43 ms
17,092 KB
testcase_39 AC 8 ms
15,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
int A[202020],B[202020];
int ma[404040];
vector<int> cand[404040];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	vector<int> Xs;
	FOR(i,M) {
		cin>>A[i]>>B[i];
		Xs.push_back(A[i]);
		Xs.push_back(B[i]);
	}
	Xs.push_back(1);
	Xs.push_back(N);
	sort(ALL(Xs));
	Xs.erase(unique(ALL(Xs)),Xs.end());
	FOR(i,M) {
		x=lower_bound(ALL(Xs),A[i])-Xs.begin();
		y=lower_bound(ALL(Xs),B[i])-Xs.begin();
		cand[y].push_back(x);
	}
	int ret=0;
	FOR(i,Xs.size()) if(i) {
		ma[i]=max(ma[i],ma[i-1]);
		FORR(e,cand[i]) ma[i]=max(ma[i],ma[e]+1);
		ret=max(ret,ma[i]);
	}
	cout<<2*N-2-ret<<endl;
		
		
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0