結果

問題 No.1995 CHIKA Road
ユーザー 👑 kmjpkmjp
提出日時 2022-07-01 21:31:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 205,856 KB
実行使用メモリ 19,152 KB
最終ジャッジ日時 2023-08-17 08:50:39
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
15,624 KB
testcase_01 AC 6 ms
15,648 KB
testcase_02 AC 6 ms
15,660 KB
testcase_03 AC 6 ms
15,648 KB
testcase_04 AC 6 ms
15,640 KB
testcase_05 AC 6 ms
15,600 KB
testcase_06 AC 11 ms
15,900 KB
testcase_07 AC 24 ms
16,428 KB
testcase_08 AC 6 ms
15,640 KB
testcase_09 AC 6 ms
15,652 KB
testcase_10 AC 42 ms
16,932 KB
testcase_11 AC 90 ms
19,152 KB
testcase_12 AC 55 ms
16,876 KB
testcase_13 AC 31 ms
16,708 KB
testcase_14 AC 34 ms
16,736 KB
testcase_15 AC 80 ms
18,776 KB
testcase_16 AC 14 ms
16,016 KB
testcase_17 AC 59 ms
17,416 KB
testcase_18 AC 78 ms
19,036 KB
testcase_19 AC 78 ms
19,044 KB
testcase_20 AC 43 ms
17,440 KB
testcase_21 AC 39 ms
17,052 KB
testcase_22 AC 73 ms
18,756 KB
testcase_23 AC 26 ms
16,540 KB
testcase_24 AC 65 ms
18,188 KB
testcase_25 AC 17 ms
16,200 KB
testcase_26 AC 28 ms
16,604 KB
testcase_27 AC 63 ms
18,372 KB
testcase_28 AC 40 ms
17,204 KB
testcase_29 AC 76 ms
18,780 KB
testcase_30 AC 16 ms
16,212 KB
testcase_31 AC 10 ms
15,916 KB
testcase_32 AC 20 ms
16,264 KB
testcase_33 AC 61 ms
18,184 KB
testcase_34 AC 12 ms
16,040 KB
testcase_35 AC 28 ms
16,612 KB
testcase_36 AC 32 ms
16,700 KB
testcase_37 AC 72 ms
18,444 KB
testcase_38 AC 51 ms
17,708 KB
testcase_39 AC 10 ms
15,884 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