hi! Come to think of it, no one has written in English, but I wonder if scolded?
I thought I should continue writing in English, but I gave up because it was too impossible. [http://arc002.contest.atcoder.jp/tasks/arc002_3] (http://arc002.contest.atcoder.jp/tasks/arc002_3) ARC # 002 is already May last year, so it's a long time ago. It is. However, when I solved it tonight, I was embarrassed to die because the processing speed was lost even though the answer at that time was a mysterious writing style.
New answer.py
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import io
import re
import math
N=int(raw_input())
c=raw_input()
chk=['AA','AB','AX','AY',
'BA','BB','BX','BY',
'XA','XB','XX','XY',
'YA','YB','YX','YY']
cnt=1000
for i in chk:
c2=c.replace(i,'L')
for j in chk:
c3=c2.replace(j,'R')
cnt=min(cnt,len(c3))
print cnt
Since I am trying to replace AA with L or R from the list of chk without exception, I replaced AA with L in i on the first lap of the double loop, but I searched for AA in j and then A remains I'm going to look for AB, AX. Thanks to the loose time and memory limits, AC passes. Yes.
Then, the one below was written about a year and a half ago.
Old answer.py
import sys
M=raw_input()
N=raw_input()
x=[]
N2=N.replace('AA','L');N3=N2.replace('AB','R');x.append(len(N3))
N2=N.replace('AA','L');N3=N2.replace('AX','R');x.append(len(N3))
N2=N.replace('AA','L');N3=N2.replace('AY','R');x.append(len(N3))
N2=N.replace('AA','L');N3=N2.replace('BA','R');x.append(len(N3))
N2=N.replace('AA','L');N3=N2.replace('BB','R');x.append(len(N3))
N2=N.replace('AA','L');N3=N2.replace('BX','R');x.append(len(N3))
#
#During this time, I'm seriously listing all the combinations. Really.
#
N2=N.replace('YA','L');N3=N2.replace('YY','R');x.append(len(N3))
N2=N.replace('YB','L');N3=N2.replace('YB','R');x.append(len(N3))
N2=N.replace('YB','L');N3=N2.replace('YX','R');x.append(len(N3))
N2=N.replace('YB','L');N3=N2.replace('YY','R');x.append(len(N3))
N2=N.replace('YX','L');N3=N2.replace('YX','R');x.append(len(N3))
N2=N.replace('YX','L');N3=N2.replace('YY','R');x.append(len(N3))
N2=N.replace('YY','L');N3=N2.replace('YY','R');x.append(len(N3))
x.sort()
print x[0]
I've listed all the combinations by hand, but I'm happy to find the combination replaced by L in R as well. What did you write so hard?
Recommended Posts