#要復習
ほぼ日刊競プロ ABC154 D - Dice in Line
D - Dice in Line
問題文
N 個のサイコロが左から右に一列に並べてあります。左から i 番目のサイコロは 1 から piまでの pi種類の目がそれぞれ等確率で出ます。
隣接する K 個のサイコロを選んでそれぞれ独立に振ったとき、出る目の合計の期待値の最大値を求めてください。
考えたこと
まず1からpiまでしか出ないサイコロの期待値を求める.
1の時=1,2の時=1.5,3の
ほぼ日刊競プロ ABC199 C - IPFL
C - IPFL
問題文
長さ 2N の文字列 S があります。
この文字列に対して Q 個のクエリが与えられます。i 番目のクエリでは 3 つの整数 Ti,Ai,Biが与えられるので、以下の処理をします。Ti=1 のとき : S の Ai文字目と Bi文字目を入れ替えるTi=2 のとき : S の前半 N 文字と後半 N 文字を入れ替える(Ai,Biの値は用いない)
例えば S
ほぼ日刊競プロ ABC175 C - Walking Takahashi
C - Walking Takahashi
問題文
数直線上で暮らす高橋君は、今座標 X にいます。これから高橋君はちょうど K 回、座標の正または負の方向に D 移動する行為を繰り返そうと考えています。より正確には、1 回の移動では 座標 x から x+D または x−D に移動できます。高橋君は、ちょうど K 回移動した後にいる座標の絶対値が最小となるように移動したいです。K 回の移動後の座
ほぼ日刊競プロ ABC177 C - Sum of product of pairs
C - Sum of product of pairs
問題文
N 個の整数 A
1,…,ANが与えられます。
1≤i<j≤N を満たす全ての組 (i,j) についての Ai×Ajの和を mod(10^9+7) で求めてください。
考えたこと普通に2重for文ではタイムオーバーしてしまうため,効率よく計算する方法を考える.
sum = A1*A2+A1*A3+A1*A4+A2*A3+A
ほぼ日刊競プロ ABC193 C - Unexpressed
C - Unexpressed
問題文
整数 N が与えられます。 1 以上 N 以下の整数のうち、 2 以上の整数 a,b を用いて a^bと表せないものはいくつあるでしょうか?
考えたこと制約上Nの最大値は10^10なので2以上の整数aは2から10^5の範囲,bは2から多く見積もっても100で確かめればよい.
setを用いてハッシュテーブルで数を追加していく.
N=int(input()
ほぼ日刊競プロ ABC182 C - Travel
C - Travel
問題文
N 個の都市があります。都市 i から都市 j へ移動するには T
i,jの時間がかかります。
都市 1 を出発し、全ての都市をちょうど 1 度ずつ訪問してから都市 1 に戻るような経路のうち、移動時間の合計がちょうど K になるようなものはいくつありますか?
考えたことitertoolsを用いて準列を用いる.
N,K = map(int,input().s
ほぼ日刊競プロ ABC182 C - To 3 ちょっと深掘り
C - To 3
問題文
各桁に 0 が出現しないような正の整数 N が与えられます。
N の桁数を k とします。N の桁を 0 個以上 k 個未満消して、残った桁をそのままの順序で結合することで 3 の倍数を作りたいです。
3 の倍数を作ることができるか判定し、作ることができるなら作るのに必要な最少の消す桁数を求めてください。
考えたこと深く考えずにitertoolsを使った組み合わせで解を
ほぼ日刊競プロ leetcode 2. Add Two Numbers
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two
ほぼ日刊競プロ leetcode 338. Counting Bits
338. Counting Bits
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
考えたこと以下の3パターンを考えた.
1.2進数に
ほぼ日刊競プロ leetcode 283. Move Zeroes
283. Move Zeroes
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of
ほぼ日刊競プロ leetcode 543. Diameter of Binary Tree
543. Diameter of Binary Tree
Given the root of a binary tree, return the length of the diameter of the tree.
The diameter of a binary tree is the length of the longest path between any two nodes in a
ほぼ日刊競プロ leetcode 108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.
A height-balanced bina
ほぼ日刊競プロ leetcode 104. Maximum Depth of Binary Tree
104. Maximum Depth of Binary Tree
Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the
ほぼ日刊競プロ leetcode 938. Range Sum of BST
938. Range Sum of BST
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].
考えたこと上記のように2分木に