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?

ABC394振り返り

Last updated at Posted at 2025-02-22

前回の振り返り

今日はABC開催日だったので参加結果を振り返る

今週はのA,B,C,Dの4完(2ペナ)

A

内包表記のフィルター

ソースコード

main.py
print("".join(s for s in input() if s=="2"))

B

文字列の長さをkeyに設定してsortedしたものをjoin

ソースコード

main.py
n=int(input())
s = [input() for _ in range(n)]
print("".join(sorted(s,key=lambda x:len(x))))

C

適当な置換でTLEしてしまったので

WW...WWAを ACC...CCの塊をまとめて処理するようにした

ソースコード

main.py
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
import os
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
IS_LOCAL = int(os.getenv("ATCODER", "0"))==0
err = (lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)) if IS_LOCAL else (lambda *args, **kwargs: None)

def main():
    S = rS()
    s = S
    ns = ""
    w = False
    x = 0
    for c in groupby(s):
        # err(c, w, x)
        if c[0] == "W":
            w = True
            x = len(list(c[1]))
        elif w and c[0] == "A":
            next(c[1])
            ns += "A" + "C" * x + "".join(c[1])
            w = False
            x = 0
        elif w:
            ns += "W" * x + "".join(c[1])
            w = False
            x = 0
        else:
            ns += "".join(c[1])
    if w:
        ns += "W" * x + "".join(c[1])
    print(ns)

if __name__ == '__main__':
    main()

D

これも適当な置換でTLE。

スタックを使って括弧が消せる位置にあるかどうかを判断した

ソースコード

main.py
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, Counter, deque
from functools import reduce, lru_cache
from itertools import product, accumulate, groupby, combinations
import sys
import os
def rI(): return int(sys.stdin.readline().rstrip())
def rLI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def rI1(): return (int(sys.stdin.readline().rstrip())-1)
def rLI1(): return list(map(lambda a:int(a)-1,sys.stdin.readline().rstrip().split()))
def rS(): return sys.stdin.readline().rstrip()
def rLS(): return list(sys.stdin.readline().rstrip().split())
IS_LOCAL = int(os.getenv("ATCODER", "0"))==0
err = (lambda *args, **kwargs: print(*args, **kwargs, file=sys.stderr)) if IS_LOCAL else (lambda *args, **kwargs: None)

def main():
    S = rS()
    
    t = []
    ans = False
    for s in S:
        if s in "(<[":
            t.append(s)
        else:
            if len(t) == 0:break
            if s=="]" and t[-1] == "[":
                t.pop()
            if s==">" and t[-1] == "<":
                t.pop()
            if s==")" and t[-1] == "(":
                t.pop()
    else:
        ans = len(t) == 0
    print("Yes" if ans else "No")
    
            
            
    
if __name__ == '__main__':
    main()

コメント

テスト環境がトラブったのでunratedで挑んだが普通に4完した。
しかしperfが491しか出なかったので今回は早ときが必要だったパターンなようだ。

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?