マガジンのカバー画像

競技プログラミング

145
運営しているクリエイター

#python初心者

ほぼ日刊競プロ ABC193 C - Unexpressed

ほぼ日刊競プロ 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

ほぼ日刊競プロ 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 ちょっと深掘り

ほぼ日刊競プロ ABC182 C - To 3 ちょっと深掘り

C - To 3
問題文
各桁に 0 が出現しないような正の整数 N が与えられます。
N の桁数を k とします。N の桁を 0 個以上 k 個未満消して、残った桁をそのままの順序で結合することで 3 の倍数を作りたいです。
3 の倍数を作ることができるか判定し、作ることができるなら作るのに必要な最少の消す桁数を求めてください。

考えたこと深く考えずにitertoolsを使った組み合わせで解を

もっとみる
ほぼ日刊競プロ leetcode 1323. Maximum 69 Number

ほぼ日刊競プロ leetcode 1323. Maximum 69 Number

1323. Maximum 69 Number
You are given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).

考えた

もっとみる
ほぼ日刊競プロ ABC266 A - Middle Letter

ほぼ日刊競プロ ABC266 A - Middle Letter

A - Middle Letter
問題文
英小文字からなる長さが奇数の文字列 S が与えられます。
S の中央の文字を出力してください。

考えたこと文字列の数は奇数なので、文字列の数//2で割れば中心の文字列のindexが求められる。(//2で割った場合切り捨て)

 ​S= input()print (S[len(S)//2])

ほぼ日刊競プロ leetcode 2. Add Two Numbers

ほぼ日刊競プロ 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 448. Find All Numbers Disappeared in an Array

ほぼ日刊競プロ leetcode 448. Find All Numbers Disappeared in an Array

448. Find All Numbers Disappeared in an Array
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums

もっとみる
ほぼ日刊競プロ leetcode 392. Is Subsequence

ほぼ日刊競プロ leetcode 392. Is Subsequence

392. Is Subsequence
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting

もっとみる
ほぼ日刊競プロ leetcode 344. Reverse String

ほぼ日刊競プロ leetcode 344. Reverse String

344. Reverse String
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.

考えたこ

もっとみる

ほぼ日刊競プロ 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 46. Permutations

ほぼ日刊競プロ leetcode 46. Permutations

46. Permutations
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.

考えたこと配列が与えられるので,順列を生成し返せばよい.pythonにはitertoolsを使えば組み合わせや順列を生成でき

もっとみる

ほぼ日刊競プロ 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 136. Single Number

ほぼ日刊競プロ leetcode 136. Single Number

136. Single Number
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use on

もっとみる
ほぼ日刊競プロ leetcode 160. Intersection of Two Linked Lists

ほぼ日刊競プロ leetcode 160. Intersection of Two Linked Lists

160. Intersection of Two Linked Lists
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all,

もっとみる