はまやんはまやんはまやん

hamayanhamayan's blog

2019-09-01から1ヶ月間の記事一覧

Three Girls [Kodamanと愉快な仲間たち R]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/three-girls 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/three-girls/submissions/code/1316482864 3つ選択する部分があるが、3つ選ぶ系は真ん中を固定する…

Let's Shoot! [Kodamanと愉快な仲間たち L]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/lets-shoot 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/lets-shoot/submissions/code/1316478561 dpで解けそう。 添字も小さいし、こんなDPで解けるんじゃ…

異世界転生2 [Kodamanと愉快な仲間たち J]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/2-82 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/2-82/submissions/code/1316477943 パっと見てDPな感じ。 区間で、最大値で、かぶってはいけない。 今まで…

Mad Time Traveler [Kodamanと愉快な仲間たち M]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/mad-time-traveler 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/mad-time-traveler/submissions/code/1316478991 まず、時間旅行の移動を有向グラフの有向辺…

is this tournament correct? [Kodamanと愉快な仲間たち I]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/i-is-this-tournament-correct 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/i-is-this-tournament-correct/submissions/code/1316477775 クエリ問題になって…

Break PGC [Kodamanと愉快な仲間たち H]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/break-pgc 前提知識 二分探索 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/break-pgc/submissions/code/1316477241 問題文に最大値は最小でいくつになります…

disastrous gemini [Kodamanと愉快な仲間たち F]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/disastrous-gemini 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/disastrous-gemini/submissions/code/1316476143 クーラーをつけないとAi秒、つけているとBi…

Osmium_1008と時間旅行 [Kodamanと愉快な仲間たち G]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/osmium1008-and-timetravel 前提知識 最大最小系DP(メモリ節約も) 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/disastrous-gemini/submissions/code/13164…

1337 [Kodamanと愉快な仲間たち E]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/e-1337 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/e-1337/submissions/code/1316475979 すべての文字について、数値かどうか判定する。 C++だとisdigitと…

tv_program [Kodamanと愉快な仲間たち D]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/tv-program 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/tv-program/submissions/code/1316475865 とりあえず、Dが平日か週末かで場合分けしよう。 与えられ…

remainder of modulo [Kodamanと愉快な仲間たち C]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/remainder-of-modulo 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/rolled-egg/submissions/code/1316475415 入力は1018なので、C++ならlong longで取ること…

Rolled Egg [Kodamanと愉快な仲間たち B]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/rolled-egg 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/rolled-egg/submissions/code/1316475415 6個入りパックを2個か、12個入りパックを1個が最適なので…

Imaging... [Kodamanと愉快な仲間たち A]

https://www.hackerrank.com/contests/kodamanwithothers/challenges/imaging 解説 https://www.hackerrank.com/contests/kodamanwithothers/challenges/imaging/submissions/code/1316475027 ボケたい衝動を抑えて、100を出力すると満点が取れる。 void _ma…

Collatz [yukicoder 887]

https://yukicoder.me/problems/no/887 解説 https://yukicoder.me/submissions/382000 制約を見てみると、シミュレートできそうな雰囲気がある。 400回までが上限なので、ぶん回す。 int n0; //----------------------------------------------------------…

約数の総和 [yukicoder 888]

https://yukicoder.me/problems/no/888 前提知識 約数列挙 O(sqrt(N)) 解説 https://yukicoder.me/submissions/381998 約数列挙は O(sqrt(N))で行うことができる。 これをしていれば答えることができる問題。 やり方はここの約数列挙 O(sqrt(N))に概略がある…

Collatz [yukicoder 887]

https://yukicoder.me/problems/no/887 解説 https://yukicoder.me/submissions/382000 制約を見てみると、シミュレートできそうな雰囲気がある。 400回までが上限なので、ぶん回す。 int n0; //----------------------------------------------------------…

移調の限られた旋法 [yukicoder 890]

https://yukicoder.me/problems/no/890 前提知識 109+7mod上での二項係数 約数系包除原理 解説 https://yukicoder.me/submissions/382005 回転対称性について考える。 まず、beetさんが質問していたので見てみる。 回転対称性を持つとはある整数i(0

隣接3項間の漸化式 [yukicoder 891]

https://yukicoder.me/problems/no/891 前提知識 行列累乗 解説 https://yukicoder.me/submissions/382008 問題を見るとフィボナッチ数の定義に似ている。 ある項のフィボナッチ数を高速に求める方法として、行列累乗が知られている。 今回の問題もこれで解…

約数の総和 [yukicoder 888]

https://yukicoder.me/problems/no/888 前提知識 約数列挙 O(sqrt(N)) 解説 https://yukicoder.me/submissions/381998 約数列挙は O(sqrt(N))で行うことができる。 これをしていれば答えることができる問題。 やり方はここの約数列挙 O(sqrt(N))に概略がある…

素数! [yukicoder 889]

https://yukicoder.me/problems/no/889 解説 https://yukicoder.me/submissions/382002 いろいろな種類の数に対する判定をする問題。 こういうものは関数化してライブラリとして持っておこう。 完全数判定なんて、どこで使うかわからないが、いつか役立った…

アマリクエリ [yukicoder 885]

https://yukicoder.me/problems/no/885 解説 https://yukicoder.me/submissions/379434 剰余にまつわる重要な性質がある。 1度剰余が行われると、値が変わらないか、半分未満の数に変わる。 よって、各要素について値が変わる回数はlogA[i]回となる。 つまり…

約数倍数 [yukicoder 882]

https://yukicoder.me/problems/no/882 解説 https://yukicoder.me/submissions/379418 条件を満たす整数は、Aの約数なので、[1,A]のどこかにある。 なので、これを全探索して、Aの約数であってBの倍数であるものがあれば、YES そうでないならNO int A, B; /…

Eat and Add [yukicoder 884]

https://yukicoder.me/problems/no/884 解説 https://yukicoder.me/submissions/379432 操作について考えてみると、2kを足すか引くかということができる。 各位について、「2kを1度足すか、2kを1度引くか、なにもしない」の3択を選択すればいい。 2kを足して…

ぬりえ [yukicoder 883]

https://yukicoder.me/problems/no/883 解説 https://yukicoder.me/submissions/379423 構築問題は色々な方針があるが、今回は最適方針があり、それで構築する方針を取ろう。 頑張れば全部の行と列でK個配置することができる。 つまり、Mを固定したときにMK…

Range High-Element Query [yukicoder 878]

https://yukicoder.me/problems/no/878 前提知識 ダブリング 解説 https://yukicoder.me/submissions/377919 高い要素の個数を答える方針でしばらく考えていてダメだったので、 ちょっと言い換えを考えてみる。 区間が与えられた時に、先頭から順に最も近い…

Range ReLU Query [yukicoder 877]

https://yukicoder.me/problems/no/877 前提知識 セグメントツリーにセグメントツリーを乗せるテク 解説 https://yukicoder.me/submissions/377916 やりすぎ回答かもしれない。 maxという制約が入ったままだと問題としては扱いづらい。 なので、[l,r]という…

Range Compress Query [yukicoder 876]

https://yukicoder.me/problems/no/876 解説 https://yukicoder.me/submissions/377914 問題をよく見ると、隣り合う数が異なる組+1を答える問題になっている。 つまり、数の実際の大小は特に意味がない。 加えて、今回は区間addのクエリもあるため、階差を使…

Many Slimes [AtCoder Beginner Contest 140 F]

https://atcoder.jp/contests/abc140/tasks/abc140_f 解説 https://atcoder.jp/contests/abc140/submissions/7444067 まず、218は5*105くらいあるので、小さい数ではない。 割り当て問題としてマッチング問題があるが、そんな雰囲気は全然しない。 全然思い…

Face Produces Unhappiness [AtCoder Beginner Contest 140 D]

https://atcoder.jp/contests/abc140/tasks/abc140_d 解説 https://atcoder.jp/contests/abc140/submissions/7443535 400点にしてはだいぶ難しく見える。 回転というのは厄介か。 まず、重要な考察がいくつかある。 方向が一致してない箇所で幸福が1つ減る …

Second Sum [AtCoder Beginner Contest 140 E]

https://atcoder.jp/contests/abc140/tasks/abc140_e 解説 https://atcoder.jp/contests/abc140/submissions/7443801 総和を求める問題でよく使うテクであるが、「全てのパターンについてある値の総和」というのを 「(ある値×その値になる組み合わせ)の総…