Atcoder Beginners Contest 346 Recap


Welcome Atcoders to BinaryFish! In this article, we will recap Atcoder Beginners Contest #346, diving into key ideas, detailed explainations, and more. Whether you participated in this contest or not, this article will help you with your journey of competitive programming. Let’s dive in!

Tasks - UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346)
AtCoder is a programming contest site for anyone from beginners to experts. We hold weekly programming contests online.
Tasks - UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346) favicon https://atcoder.jp/contests/abc346/tasks?lang=en
Tasks - UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346)

Problem A-> Adjacent Product

This problem had decent difficulty, but it should be a question that most coders can answer. Here is the problem.

You are given N integers . Also define . Print in this order, separated by spaces.

Guide

So the only two things you have to do in order to solve this problem is

  1. Create a list with every
  2. Sperate the results with spaces, then print it.

It took about 7 minutes to get AC on this problem. My code is not the simplest way of solving this problem, but still I got it right.

Here is the code that does the two things and got AC on Atcoder.

Answer

# -*- coding: utf-8 -*-
# Get Inputs
N = int(input())
As = input().split()
# Array to store the results
Bs = []

# Cacuculate
for i in range(0,N-1):
    Bs.append(int(As[i])*int(As[i+1]))
# Bss is the variable that gets printed
Bss = ""
# For loop for formatting the answers
for i in range(0,len(Bs)):
    Bss = Bss +str(Bs[i] )  + " "
print(Bss)

Problem B => Piano

Problem B was the problem that I got stuck on. Usually, I am able to atleast correctly answer both A and B, but I couldn’t in this competition. I strongly belives that this question is one of the hardest problem B in all of the Atcoder Beginners Contest. Still, I solved this problem afterwards so I will write a recap here.

Here is the problem.

There is an infinitely long piano keyboard. Is there a continuous segment within this keyboard that consists of W white keys and B black keys? Let S be the string formed by infinitely repeating the string wbwbwwbwbwbw. Is there a substring of S that consists of W occurrences of w and B occurrences of b?

Guide

So this problem is type of problem that has numerous way to solve it. For instance, the official explanation uses a strategy with mod, but here I used a simpler method inspired by code of a youtube @EbimaLabo. After the competition, I looked at his code and analyzed what was really happening. Here is the result of my analysis and adaptation to it.

Firstly, you have to create a reccuring String “Wbwbwwbwbwbw” that has exact length as length of original String and values of W and B. Next, test if the certain section of the String contains exact number of “w” as the given value. If there is a section, then print Yes, and if not print No.

That is the basic algorythm that is used to solve this problem. Here is my adapted code that got AC, (the original version from @ebimalabo).


# -*- coding: utf-8 -*-
Letter = "wbwbwwbwbwbw"

W,B = map(int,input().split())
NewString = Letter * (W+B)
answer = False
# Repeat 12 times (The length of original String)
for i in range(len(Letter)):
    answer |= NewString[i : i + W + B ].count("w") == W
# If answer is true then print Yes, if not print No
if answer:
    print("Yes")
else:
    print("No")

Full problem explaination by EbimaLabo

Here is a Youtube Video I found that explains every problem. This guide walked through only the As and Bs so if you need more guide, this would definently help. The audio is in Japanese, but it should be not be that hard to undertsand with auto translation of subtitles.

Conclusion

The contest 346 was a good contest, with new types of problems and skills I worked on. I apologize that I only put two questions in this guide, but it would be greatly appreciated if you can understand that I am a beginner Atcoder. Thank you for reading.

Share this page