結果

問題 No.22 括弧の対応
ユーザー ノットカワズノットカワズ
提出日時 2016-05-14 23:28:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 556 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 7,956 KB
最終ジャッジ日時 2023-09-27 13:06:11
合計ジャッジ時間 1,362 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,756 KB
testcase_01 AC 16 ms
7,768 KB
testcase_02 AC 16 ms
7,840 KB
testcase_03 AC 16 ms
7,732 KB
testcase_04 AC 17 ms
7,860 KB
testcase_05 AC 16 ms
7,844 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 16 ms
7,852 KB
testcase_08 AC 16 ms
7,776 KB
testcase_09 AC 16 ms
7,804 KB
testcase_10 AC 16 ms
7,836 KB
testcase_11 AC 16 ms
7,768 KB
testcase_12 AC 16 ms
7,920 KB
testcase_13 AC 17 ms
7,792 KB
testcase_14 AC 16 ms
7,956 KB
testcase_15 AC 16 ms
7,852 KB
testcase_16 AC 16 ms
7,788 KB
testcase_17 AC 16 ms
7,780 KB
testcase_18 AC 16 ms
7,804 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:6: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if S[i] is '(':
Main.py:16: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if check is 1:
Main.py:17: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while check is not 0:
Main.py:17: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while check is not 0:
Main.py:21: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if check is -1:
Main.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while check is not 0:
Main.py:22: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while check is not 0:

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-


def CheckAns(i, S):
    if S[i] is '(':
        return 1
    else:
        return -1


def kakko(K, S):
    check = CheckAns(K - 1, S)
    i = K - 1

    if check is 1:
        while check is not 0:
            i += 1
            check += CheckAns(i, S)

    if check is -1:
        while check is not 0:
            i -= 1
            check += CheckAns(i, S)

    return i + 1


def main():
    N, K = map(int, input().split())
    S = input()

    print(kakko(K, S))


if __name__ == '__main__':
    main()
0