0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【競技プログラミング】AtCoder Beginner Contest 405

Posted at

既存投稿一覧ページへのリンク

一覧ページ

Before

AtCoder Beginner Contest 404

Next

AtCoder Beginner Contest 406

C問題

入力例01

この問題は累積和でよく解いた問題よね。さすがに無事AC

ac_python

ac.py
def io_func():
    n = int(input())             # 整数Nを標準入力から取得
    a = list(map(int, input().split()))   # N個の整数Aを標準入力から取得しリスト化
    return n, a                  # 変数n(整数)、a(リスト)を戻り値として返す

def solve(n, a):
    s = a.copy()
    for i in range(1, n):
        s[i] = s[i-1] + a[i]
    ans = 0
    for i in range(n):
        if i<n:
            ans += a[i] * (s[n-1] - s[i])

    print(ans)

if __name__=="__main__":
    n, a = io_func()
    solve(n, a)

D問題

雑記

パット見の方針、"E"の座標を抽出し、そこからBFSすれば良いんじゃない?と感じたので実装。

input

7 20
....................
..#..#..####..#E##..
..#..#..#..#..#.....
..E###..#..#..####..
.....#..#..E.....#..
.....#..####..####..
....................

input_python

input.py
def io_func():
    # 行数と列数を整数で取得
    h, w = map(int, input().split())
    # 盤面データ(各行ごと)を格納するリスト
    s = []
    for _ in range(h):
        line = input()  # 1行分の入力を受け取る
        s.append(line)  # 文字列としてリストへ格納
    # 変数h, w, sをタプルで返す
    return h, w, s

output

>v<<<<<>>>>>>>>v<<<<
>v#^<#^^####v^#E##vv
>v#^<#v^#>v#vv#^<<<<
>>E###vv#>v#vv####^<
>>^<<#vv#>>E<<<<<#^<
>>^<<#vv####^<####^<
>>^<<<<<>>>>^<<<<<^<

E問題

入力例01

あなたは、

  • リンゴが 3 個
  • オレンジが 1 個
  • バナナが 4 個
  • ブドウが 1 個

を持っています。

これら 合計で 3 + 1 + 4 + 1 = 9 個の果物 を、以下の すべての条件を満たすように 左右一列に並べたいと考えています。

  • リンゴは すべてバナナよりも左側に並べること
  • リンゴは すべてブドウよりも左側に並べること
  • オレンジは すべてブドウよりも左側に並べること

ただし、同じ種類の果物同士は区別できません

このとき、並べ方は何通りありますか?
答えは 998244353 で割った余りを出力してください。

input

3 1 4 1

input_python

input.py
def io_func():
    # 標準入力から1行を読み取り、空白区切りで分割して整数に変換
    a, b, c, d = map(int, input().split())
    
    # 4つの整数をタプルとして戻り値にする
    return a, b, c, d
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?