This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use petgraph::prelude::*; | |
use petgraph::algo::{min_spanning_tree, connected_components}; | |
use petgraph::data::FromElements; | |
fn main() { | |
proconio::input!{ n: usize, m: usize, clr: [(i64, usize, usize); m], }; | |
let lrc: Vec<_> = clr.into_iter().map(|(c, l, r)| (l-1, r, c)).collect(); | |
let g = UnGraph::<(), _, _>::from_edges(&lrc); | |
if g.node_count() < n+1 || connected_components(&g) > 1 { println!("-1"); return; } | |
let mst = UnGraph::<_, _>::from_elements(min_spanning_tree(&g)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
use proconio::{input, marker::Chars}; | |
const MOD: u32 = 1_000_000_007; | |
fn main() { | |
input! { h: usize, w: usize, c: [Chars; h], }; | |
let mut dp = HashMap::with_capacity(200000); | |
dp.insert(0u32, 1u32); | |
for i in 0..h { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use itertools::Itertools; | |
fn main() { | |
proconio::input! { n: i64, b: i64, }; | |
let mut log10b = 0; | |
while 10i64.pow(log10b) <= b { log10b += 1; } | |
let log10b = log10b as usize; | |
let digits_iter = (0..=9).combinations_with_replacement(log10b); | |
let mut ans = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::Cell; | |
use proconio::{input, marker::Chars}; | |
#[derive(Debug)] | |
struct GridGraph { | |
h: usize, | |
w: usize, | |
c: Vec<Vec<char>>, | |
} | |
impl GridGraph { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// B[i] = ((-1)^i)*A[i]とおく (iは0-indexed. 以下小文字の添字はは0_indexed) | |
// T=0 で与えられる情報は(-1)^x * B[x] + (-1)^(x+1) * B[x+1] = V | |
// diff_b[x] = B[x+1] - B[x]と定義すると、diff_b[x] = -(-1)^x * V | |
// T=1 でB[x]が与えられるので、例えば x<y の場合、diff_b[x], .., diff_b[y-1]が判明していればB[y]が求められる。 | |
// diff_b[x] + .. + diff_b[y-1]を高速に計算するためにBITを利用する。 | |
// diff_b[x], .., diff_b[y-1]が全て判明しているかもBITで管理する。 | |
use proconio::{input, fastout, marker::Usize1}; | |
#[fastout] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
using pii = pair<int, int>; | |
// QueryId: クエリId -> (Edges: 必要な辺数, Depth: 最小共通祖先(LCA)) のmap | |
using QED = unordered_map<int, pii>; | |
#define rep(i, n) for (int i=0; i<n; i++) | |
vector<int> depth; | |
vector<vector<int>> to, ids; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use itertools::Itertools; | |
use superslice::Ext; | |
// 部分列からちょうどk個選び、p以下の和のみ列挙 | |
// 部分列の長さが0またはk=0の場合は{0}を返す。どのk個を選んでもpを超える場合は{}を返す。 | |
fn sums(a_slice: &[i64], p: i64, k: usize) -> Vec<i64> { | |
let mut sums: Vec<_> = a_slice.iter().combinations(k) | |
.map(|v| v.into_iter().sum::<i64>() ) | |
.filter(|&s| s <= p ) | |
.collect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use proconio::{input, fastout}; | |
use std::collections::VecDeque; | |
const QMAX: usize = 100000; | |
#[fastout] | |
fn main() { | |
let mut data = VecDeque::with_capacity(QMAX); | |
input! { tx: [(usize, usize)], }; | |
for txi in tx { | |
match txi { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MAX: i32 = std::i32::MAX; | |
struct LIS { | |
n: usize, | |
data: Vec<i32>, | |
} | |
impl LIS { | |
fn new(n: usize) -> Self { | |
Self { n, data: vec![MAX; n], } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use proconio::{input, marker::Usize1, fastout}; | |
use std::collections::BinaryHeap; | |
use std::cmp::Reverse; | |
const MAX: i64 = std::i64::MAX; | |
#[allow(dead_code)] | |
struct Graph { | |
n: usize, | |
m: usize, | |
edges: Vec<Vec<(usize, usize, i64)>>, |