Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AGC043Aで生成されるテンプレート生成の誤り?について #203

Open
rkxy01 opened this issue Jun 7, 2020 · 1 comment
Open

Comments

@rkxy01
Copy link

rkxy01 commented Jun 7, 2020

AGC043Aにおいて、

atcoder-tools gen agc043

というコードを実行したところ、次のようなテンプレートが出力されております。

#!/usr/bin/env python3
import sys


def solve(H: int, W: int, s: "List[str]"):
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

https://atcoder.jp/contests/agc043/tasks/agc043_aにあるように、入力ケースはsは(H, W)サイズの2重リストであることが期待されるべきですが、生成されているケースは(W, W)になっているように見受けられます。

おそらく、

    s = [next(tokens) for _ in range(W)]  # type: "List[str]"

    s = [next(tokens) for _ in range(H)]  # type: "List[str]"

であるべきだと思います。

例えば、以下のコードにおいて、range(W)はWA、range(H)はACとなっています。

#!/usr/bin/env python3
import sys


def solve(H: int, W: int, s: "List[str]"):
    dp = [[0 for w in range(W)] for h in range(H)] # dp[h][w]はh,wに達するための回数
    if s[0][0] == '#':
        dp[0][0] = 1

    for w in range(W-1):
        if s[0][w+1] == '.':
            dp[0][w+1] = dp[0][w]
        elif s[0][w] == '.' and s[0][w+1] == '#':
            dp[0][w+1] = dp[0][w] + 1
        elif s[0][w] == '#' and s[0][w+1] == '#':
            dp[0][w+1] = dp[0][w]

    for h in range(H-1):
        if s[h+1][0] == '.':
            dp[h+1][0] = dp[h][0]
        elif s[h][0] == '.' and s[h+1][0] == '#':
            dp[h+1][0] = dp[h][0] + 1
        elif s[h][0] == '#' and s[h+1][0] == '#':
            dp[h+1][0] = dp[h][0]

    for h in range(1, H):
        for w in range(W-1):
            if s[h][w+1] == '.':
                dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
            elif s[h][w] == '.' and s[h][w+1] == '#':
                if s[h-1][w+1] == '.':
                    dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1]+1)
                elif s[h-1][w+1] == '#':
                    dp[h][w+1] = min(dp[h][w]+1, dp[h-1][w+1])
            elif s[h][w] == '#' and s[h][w+1] == '#':
                if s[h-1][w+1] == '.':
                    dp[h][w+1] = min(dp[h][w], dp[h-1][w+1]+1)
                elif s[h-1][w+1] == '#':
                    dp[h][w+1] = min(dp[h][w], dp[h-1][w+1])
    print(dp[H-1][W-1])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # ここがWで出力されているが、Hに要修正?
    solve(H, W, s)

if __name__ == '__main__':
    main()
@rkxy01
Copy link
Author

rkxy01 commented Jun 7, 2020

過去のIssueを見たところ、
#185
と同じような症状のようですね…

一応ご報告のためにも残しておきます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant