[PYTHON] AtCoder Regular Contest # 002 C Problem

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

AtCoder Regular Contest # 002 C Problem
AtCoder Beginner Contest # 002 C Problem
AtCoder Beginner Contest 174 C Problem (Python)
AtCoder Regular Contest 105 Review
AtCoder Regular Contest 106 Note
AtCoder Regular Contest 105 Note
AtCoder Regular Contest 106 Review
AtCoder Regular Contest 104 Review
AtCoder Regular Contest 105 Participation Report
AtCoder Regular Contest 104 Participation Report
AtCoder Beginner Contest 176 C Problem "Step" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 B Problem "Distance" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 169 B Problem "Multiplication 2" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 177
AtCoder Beginner Contest 170 A Problem "Five Variables" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 179
AtCoder Beginner Contest 169 A Explanation of Problem "Multiplication 1" (Python3, C ++, Java)
AtCoder Beginner Contest 176 A Explanation of problem "Takoyaki" (Python3, C ++, Java)
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 175 B Problem "Making Triangle" Explanation (C ++, Python3, Java)
AtCoder Beginner Contest 173
AtCoder Beginner Contest 175 A Problem "Rainy Season" Explanation (C ++, Python3, Java)
Atcoder Beginner Contest 153
AtCoder Beginner Contest 176 B Problem "Multiple of 9" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 174 A Problem "Air Conditioner" Explanation (C ++, Python, Java)
AtCoder Beginner Contest 173 B Problem "Judge Status Summary" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 170 B Problem "Crane and Turtle" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 177 C Problem "Sum of product of pairs" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 165 A Problem "We Love Golf" Explanation (Python3, C ++, Java)
AtCoder Beginner Contest 167 B Problem "Easy Linear Programming" Explanation (Python3, C ++, Java)
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 181 Note
AtCoder Grand Contest 041 Review
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 167 Review
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 164 Review
AtCoder Beginner Contest 169 Review
AtCoder Beginner Contest 181 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 180 Review
AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Grand Contest 045 Review
AtCoder Grand Contest 044 Review
AtCoder Beginner Contest 179 Review
Solve AtCoder Beginner Contest 100-102
AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 184 Note
AtCoder Grand Contest 046 Review
AtCoder Beginner Contest 175 Review