結果

問題 No.1995 CHIKA Road
ユーザー 👑 NachiaNachia
提出日時 2022-07-01 22:45:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 92,116 KB
実行使用メモリ 17,192 KB
最終ジャッジ日時 2023-08-17 10:20:10
合計ジャッジ時間 3,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 21 ms
5,972 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 39 ms
5,944 KB
testcase_11 AC 92 ms
17,192 KB
testcase_12 AC 63 ms
10,888 KB
testcase_13 AC 29 ms
7,836 KB
testcase_14 AC 31 ms
8,032 KB
testcase_15 AC 79 ms
15,472 KB
testcase_16 AC 11 ms
4,600 KB
testcase_17 AC 43 ms
9,016 KB
testcase_18 AC 72 ms
12,764 KB
testcase_19 AC 72 ms
12,844 KB
testcase_20 AC 39 ms
8,556 KB
testcase_21 AC 36 ms
7,948 KB
testcase_22 AC 68 ms
12,156 KB
testcase_23 AC 22 ms
5,980 KB
testcase_24 AC 59 ms
11,104 KB
testcase_25 AC 13 ms
4,856 KB
testcase_26 AC 25 ms
6,508 KB
testcase_27 AC 57 ms
10,836 KB
testcase_28 AC 35 ms
7,960 KB
testcase_29 AC 71 ms
12,508 KB
testcase_30 AC 12 ms
4,784 KB
testcase_31 AC 6 ms
4,380 KB
testcase_32 AC 16 ms
5,448 KB
testcase_33 AC 57 ms
10,684 KB
testcase_34 AC 7 ms
4,380 KB
testcase_35 AC 24 ms
6,380 KB
testcase_36 AC 27 ms
6,816 KB
testcase_37 AC 66 ms
11,952 KB
testcase_38 AC 46 ms
9,284 KB
testcase_39 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <atcoder/modint>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<1000000007>;

template<class T> using nega_queue = priority_queue<T, vector<T>, greater<T>>;


struct Edge { int to; int dist; };


int main(){
	int N; cin >> N; N--;
	int M; cin >> M;
	vector<int> idxs;
	vector<int> A(M);
	vector<int> B(M);
	rep(i,M){
		cin >> A[i]; A[i]--;
		cin >> B[i]; B[i]--;
	}
	rep(i,M){
		idxs.push_back(A[i]);
		idxs.push_back(B[i]);
	}
	idxs.push_back(0);
	idxs.push_back(N);

	sort(idxs.begin(), idxs.end());
	idxs.erase(unique(idxs.begin(), idxs.end()), idxs.end());
	auto getidx = [&](int x) -> int { return lower_bound(idxs.begin(), idxs.end(), x) - idxs.begin(); };

	int n = idxs.size();
	vector<vector<Edge>> adj(n);
	rep(i,M){
		adj[getidx(A[i])].push_back({ getidx(B[i]), 2*B[i] - 2*A[i] - 1 });
	}
	rep(i,n-1){
		adj[i].push_back({ i+1, 2*idxs[i+1] - 2*idxs[i] });
	}

	vector<i64> dist(n, INF);
	dist[0] = 0;
	rep(i,n) for(auto edge : adj[i]) dist[edge.to] = min(dist[edge.to], dist[i] + edge.dist);
	
	cout << dist.back() << '\n';
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0