I wanted to solve ABC159 in Python

Introduction

This time the problem was simple, so I could solve A ~ C, but I should have solved D.

A problem

Problem

** Thoughts ** To make an even number, there are only even numbers + even numbers and odd numbers + odd numbers, so $ _nC _r $ and $ _mC _r $ are used for N and M, respectively. You can implement the combination calculation yourself, but I used it because it is in scipy.

from scipy.misc import comb
n, m = map(int,input().split())

ans = comb(n,2,exact=True) + comb(m,2,exact=True) #exact=True returns an integer value
print(ans)

B problem

Problem

** Thoughts ** I was not good at palindromes, so I left it after solving A. If S is a palindrome, we solved it using s.reverse () == s. The strong palindrome condition sliced s and did the same as above. n

s = list(str(input()))

checker = 0
n = len(s)
new_s = list(reversed(s))
if s == new_s:
    checker += 1


split_s = s[0:(n-1)//2]
new_s = list(reversed(split_s))
if new_s == split_s:
    checker += 1


split_s = s[(n+2)//2:n]
new_s = list(reversed(split_s))
if new_s == split_s:
    checker += 1
if checker == 3:
    print('Yes')
else:
    print('No')

C problem

Problem

** Thoughts ** The maximum volume is when it becomes a cube, so it ends with $ (L / 3) ^ 3 $. I was afraid of the accuracy, but I passed without doing anything.

l = int(input())
print((l/3)**3)

D problem

Problem 1WA、4TLE

** Thoughts ** Couldn't solve I tried to calculate the combination with A without $ A_i $ in the for statement, but I got TLE and died.

from scipy.misc import comb

n = int(input())
a = list(map(int,input().split()))
a_s = set(a)
for i in range(n):
    l = a[i]
    a[i] = 'X'
    ans = 0
    for j in a_s:
        ans += comb(a.count(j),2,exact=True)
    print(ans)
    a[i] = l

Summary

The cause of the defeat was lack of study and giving up solving B. good night.

Recommended Posts

I wanted to solve ABC159 in Python
I wanted to solve ABC160 with Python
I wanted to solve ABC172 with Python
Solve ABC169 in Python
I wanted to solve NOMURA Contest 2020 with Python
Solve ABC176 E in Python
Solve ABC175 D in Python
I wanted to solve the ABC164 A ~ D problem with Python
Solve Atcoder ABC169 A-D in Python
Solve ABC036 A ~ C in Python
Solve ABC037 A ~ C in Python
I wanted to solve the Panasonic Programming Contest 2020 with Python
I tried to implement PLSA in Python
Solve ABC175 A, B, C in Python
I tried to implement permutation in Python
ABC 157 D --Solve Friend Suggestions in Python!
I tried to implement PLSA in Python 2
I tried to implement ADALINE in Python
I tried to implement PPO in Python
Solve ABC165 A, B, D in Python
Implemented DQN in TensorFlow (I wanted to ...)
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I wanted to do something like an Elixir pipe in Python
Solve ABC168D in Python
Solve ABC167-D in Python
Solve ABC146-C in Python
Solve ABC098-C in Python
Solve ABC159-D in Python
Solve ABC160-E in Python
I want to do Dunnett's test in Python
I was able to recurse in Python: lambda
I want to create a window in Python
I wanted to install Python 3.4.3 with Homebrew + pyenv
I wrote "Introduction to Effect Verification" in Python
I want to merge nested dicts in Python
I want to solve APG4b with Python (Chapter 2)
I tried to implement selection sort in python
I want to display the progress in Python!
I tried to solve AtCoder's depth-first search (DFS) in Python (result: TLE ...)
I tried to graph the packages installed in Python
I want to embed a variable in a Python string
Solve addition (equivalent to paiza rank D) in Python
I wrote python in Japanese
Solve AtCoder ABC166 with python
To flush stdout in Python
Atcoder ABC164 A-C in Python
Solve multiplication (equivalent to paiza rank D) in Python
Login to website in Python
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I tried to solve the soma cube with python
I tried to implement a pseudo pachislot in Python
I wanted to use the Python library from MATLAB
Atcoder ABC167 A-D in Python
I want to randomly sample a file in Python
Solve Wooldridge exercises in Python
I tried to implement Dragon Quest poker in Python
I want to solve Sudoku (Sudoku)
I was addicted to scraping with Selenium (+ Python) in 2020
I tried to implement GA (genetic algorithm) in Python
Atcoder ABC165 A-D in Python