This file contains 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::{fastout, input}; | |
#[fastout] | |
fn main() { | |
input! { n: usize, }; | |
for tmp in 0..(1 << n) { // 上位ビットが文字列の左側に相当 | |
let mut cnt = 0; | |
let mut ok = true; | |
for i in (0..n).rev() { // 上位ビットから順に走査 | |
if (tmp >> i) & 1 == 0 { |
This file contains 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::{fastout, input, marker::Usize1}; | |
use std::collections::VecDeque; | |
const NIL: i32 = -1; | |
const AUTHORS: usize = 100000; | |
const PAPERS: usize = 100000; | |
#[derive(Debug)] | |
struct Graph { | |
n: usize, | |
to: Vec<Vec<usize>>, |
This file contains 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
// from scratch is: | |
// https://gist.github.com/tokugh/ba6abbf56482e222cdf06d3148b24c45 | |
use petgraph::{prelude::*, graph::node_index}; | |
use petgraph::algo::dijkstra; | |
use proconio::{input, fastout}; | |
#[fastout] | |
fn main() { | |
input! { n: usize, abc: [(u32, u32, i32)], }; | |
let mut g = UnGraph::<(), i32>::from_edges(abc); |
This file contains 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)>>, |
This file contains 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 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 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 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 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 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 { |
OlderNewer