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

AtCoder Beginner Contest 312 D

https://atcoder.jp/contests/abc312/tasks/abc312_dDPですね。'('が出てきたら右に進んで、')'が出てきたら上に進みます。'?'ならどちらにも進めます。 // Count Bracket Sequences #![allow(non_snake_case)] use std::cmp::min; //////////////////// con…

アルゴリズムと数学 086

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bp0からはじめて、(が来たら+1、)が来たら-1として、負になったらアウトです。 // Parentheses Check #![allow(non_snake_case)] //////////////////// library /////////////////…

AtCoder Beginner Contest 311 D

https://atcoder.jp/contests/abc311/tasks/abc311_d進める方向すべてに進めばいいだけですね。 // Grid Ice Floor #![allow(non_snake_case)] use std::collections::BTreeSet; //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mu</t:>…

アルゴリズムと数学 085(2)

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bo積のほうから求める方法もありますが、手間がかかりますね。 // Two Conditions #![allow(non_snake_case)] use std::collections::HashMap; //////////////////// library ////…

アルゴリズムと数学 085

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bo三重に回せばいいので余裕で間に合います。 // Two Conditions #![allow(non_snake_case)] use std::cmp::{min, max}; //////////////////// library //////////////////// fn r…

アルゴリズムと数学 084

https://atcoder.jp/contests/math-and-algorithm/tasks/panasonic2020_cならNoです。 そうでないとき二乗して、 これが成り立つかを計算します。 // Sqrt Inequality #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr></t:>…

AtCoder Beginner Contest 310 F

https://atcoder.jp/contests/abc310/tasks/abc310_fDPで今の和の集合を状態とします。この集合を整数で表しますとよいです。ただし、10より大きい和は無視してよいです。0は必ずあるので、この状態の整数は奇数になりますが、10を含む状態を0で表せば、1023…

AtCoder Beginner Contest 310 E

https://atcoder.jp/contests/abc310/tasks/abc310_eDPですね。でを固定したとき、0になるものと1になるもののカウントしたものを状態と考えて、の状態を計算します。 // NAND repeatedly #![allow(non_snake_case)] //////////////////// library /////////…

AtCoder Beginner Contest 310 D

https://atcoder.jp/contests/abc310/tasks/abc310_dしらみつぶしすればよいです。選手を1から順にチームに配置しますが、左に空いているチームを作らないように配置します。ここで、チームの選手の集合をビットを使うと書きやすいです。 // Peaceful Teams …

AtCoder Beginner Contest 309 D

https://atcoder.jp/contests/abc309/tasks/abc309_d2つグラフを作って、それぞれ最長距離を求めます。 // Add One Edge #![allow(non_snake_case)] use std::collections::VecDeque; //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { l</t:>…

アルゴリズムと数学 083

https://atcoder.jp/contests/math-and-algorithm/tasks/typical90_nAとBの両方をソートして距離を取ります。 // We Used to Sing a Song Together #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut </t:>…

アルゴリズムと数学 082

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bn終了時刻でソートすればよいです。 // Interval Scheduling Problem #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut </t:>…

アルゴリズムと数学 081

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_bm倍数、倍数の関係になっているので、上位の札から枚数を数えていくだけですね。 // Bill Changing Problem #![allow(non_snake_case)] //////////////////// library //////////…

アルゴリズムと数学 080

https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_blダイクストラ法ですね。 // Difference Optimization 2 #![allow(non_snake_case)] use std::collections::BinaryHeap; //////////////////// library //////////////////// fn …

AtCoder Beginner Contest 308 E

https://atcoder.jp/contests/abc308/tasks/abc308_eAの組合せで分けて考えると楽になります。 // MEX #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().rea</t:>…

AtCoder Beginner Contest 308 D

https://atcoder.jp/contests/abc308/tasks/abc308_dグラフにして、最初と最後が繋がっているかを調べます。 // Snuke Maze #![allow(non_snake_case)] use std::ops::{Add, Sub}; use std::collections::HashMap; //////////////////// library ///////////…

アルゴリズムと数学 079

https://atcoder.jp/contests/math-and-algorithm/tasks/abc139_dをで割った余りと考えると、少しわかりやすいです。ならとしたときが最大です。と考えていくと簡単です。 // ModSum #![allow(non_snake_case)] //////////////////// library //////////////…