matthew as a q.

競技プログラミングメイン

2020-07-01から1ヶ月間の記事一覧

ダイクストラ法と経路復元

蟻本ベースにサンプルコードをきちんと書いたので、メモを残しておきます。 コード struct edge { public: int to; int cost; }; // O(|E|(log|V|)) void dijkstra(std::vector<int> &dist, const std::vector<std::vector<edge>> &graph, int s) { typedef std::pair<int, int> P; std::prior</int,></std::vector<edge></int>…

競技プログラミングtips(特定範囲の条件満たす要素数え上げ)

想定問題形式 「L以上、R以下の整数値のうち、条件にあてはまるものを数えよ。」というような形式を想定。 取り組み方 1..L-1、1...Rと分けて、(1..Rで条件を満たす数) - (1..L-1で条件を満たす数) として計算