We will hold UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346).
- Contest URL: https://atcoder.jp/contests/abc346
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20240323T2100&p1=248
- Duration: 100 minutes
- Writer: yuto1115, cn449, physics0523, nok0, kyopro_friends, leaf1415, ynymxiaolongbao
- Tester: sotanishy, toam
- Rated range: ~ 1999
- The point values: 100-200-250-400-450-525-575
We are looking forward to your participation!
Hope to solve a,b,c,d,e.
I hope all problems are Div3 type only.
Atcoder Beginner contest == Codeforces Div 3
Hope to solve ABCDEF.
Hope to solve ABCDE. I hope I won't be hacked this time
Hope to solve ABCD
Hope to solve ABCDE
Problem E is almost the same as 2023 Chinese NOI Spring Test Problem A. 涂色游戏 (paint), and is an easy version of LGR-162-Div.3 Problem D. 头 which I coauthored.
Please, can somebody tell me why this fails on F it literally binary searches the first left position to place "K" characters for every character in T. These contests are literally implementation only and I hate every minute of it.
16xAC 37xWA Link
I deducted the n^2 brute force solution mentioned at the end of G's editorial in 5 min, but just can't find a way to use a data structure to optimize it:( maybe i just ain't Chinese enough:P
registered 5 months ago and already master, i am pretty sure that you are chinese D:
In sweepline you add and remove segments. Use a lazy segment tree to maintain the number of segments that cover each point. Adding is += 1 on a range and removing is -= 1 on a range. Query union length after each operation. It is n minus the count of zeros. The count of zeros is the count of minimums if the minimum is zero and zero otherwise code
yeah i figured out the sweepline part with ease but couldnt think of the sgt part...
wtf is F, I cannot understand why this fails: binsearch on K, for checking each character, binsearch again on how far we have to go
I did the same thing but idk where I'm getting 2 WAs from.
For me, the 2 WAs was because of limits of binary search. Initially I put high to be 1e18 but I don't know why this was causing 2 WAs. Changing it to n*(size of s) worked. 1e18 probably caused overflow somewhere i don't know why. But even 1e17 limit which is 1e12*1e5 was causing 1 WA.
The upper bound of length is (n*(size of s))/(size of t),if you take a take k such that k*(size of t) > 2^63,it can overflow.
ohh yeah, wierd 1e17 failed, but n*(size of s) passed and I don't think it is possible that they did not put n = 1e12 and |s| = 1e5 testcase. Maybe i got lucky lol.
Try this test: n = 1
s = a
t = aaaaa
ans = 0
Me:
The answer is 1 and my code output 0. Now I fixed the code by this test.
Had the same issue where I put 1e18 and got 2 WAs. Turns out this is because of overflows on long longs when you do the binary search. Switching to bigint made it AC.
Me too,I used "long long" at first and got "WA",and I used "unsigned long long" and got "AC".
This works, i did the same thing, code -Link
Did the same and failed 37 WA lol. It's a shit problem tbh just implementationforces.
It may be beneficial for you to focus on improving your implementation or at least debugging skills. It's unfortunate to miss out on some good points because of silly bugs but it's on you.
first time with Corona Virus (just to D sadness)say no more go to sleep
Is F binary search on answer and for each search, you binary search to find when you have enough letters? My solution was n(logn^2) but it TLEs on a couple cases.
Binary search for problem F will work perfectly. I used binary search for problem F and got accepted.
Here is my submission link : https://atcoder.jp/contests/abc346/submissions/51615694
Let, p = s.size() and q = t.size()
Then, time complexity : O(q * log(1e17) * log(p))
Sorry for necroposting. I've just got TLE with your solution (which is also the intended one), I failed to optimize the constant, so I decided to write $$$O(n \log(ns))$$$, which is not that different.
You can binary search the answer by adding one bit at a time. Let $$$A$$$ be the candidate answer in some moment. Note that you only need jumps of length $$$A$$$. Given the jumps of length ($$$A$$$ without one bit), you can precalculate all jumps of length $$$A$$$ in $$$O(n)$$$. Then you can verify if $$$A$$$ is larger than the answer in $$$O(n)$$$.
Today was a bit on easier side..could solve upto E :)
How to solve D using DP ?
you can do it with prefix sum
can u explain prefix sum approach?
link
sorry i really not getting your ideas can you explain more?
you have to make string such that s[i] == s[i + 1] for exactly one i and the const should be minimum the idea is calculate cost for all possible i for both cases s[i] == 1 and s[i] == 0
code
how to do D with dp?
$$$dp[pos][prev][count]$$$
pos = current position
prev= value of previous character
count = min( 2 ,count of $$$1 \le i \le n-1$$$ where $$$s_i=s_i+1$$$)
for s[i] == s[i + 1] you just have to make sure either on the left for all k <= i parity of k == s[k] and on the right k >= i + 1 parity of k != s[k] or vice versa
i am getting wrong on 3 test cases. What have i missed?
https://atcoder.jp/contests/abc346/submissions/51621500
Solved all problems after so many contests, thank you for the contest
I have an edge case for problem F.
testcase :
2
aaa
aa
expected output : 3
But output of my accepted code for this testcase is 1. So, my code should got WA verdict. But my code got accepted.
Here is my submission link : https://atcoder.jp/contests/abc346/submissions/51615694
Mine gives 3 lmao but still fails 37 cases. Can you try finding a counter for mine please?
Submission
Take a look at Ticket 17424 from CF Stress for a counter example.
Thanks so much, I rounded one division down instead of up and messed up whole problem. :(
10 yyqml y answer should be 20 , your code gives 21
I got it, I rounded down division in one place instead of up. Thanks.
I have a question for problem B. I solved it in this manner: https://atcoder.jp/contests/abc346/submissions/51573486.
I was curious though, what if the values of W and B are very large(upto 1e18 or 1e9). In that case how will I be able to approach the problem. Is that even solvable? I am not able to think of any solution .Any help would be appreciated. Thank you
Iterate over all starting points on the string and calculate how many strings you need for b since there are less occurences of b in the strings and then iterate over the remainder of the string.
yes
if there's a substring it will be of the form
some suffix of s + x times s + some prefix of s
now as size of s is small we check the condition for all possible prefix and suffix pairIn B, how answer is "No" for W=7,B=5???
the answer is Yes for w=7 and b=5
that's the original string itself so the answer is Yes
absolutely interesting problem, G is hard but the tutorial is very clear.
This Round was really amazing. I really enjoyed this round. The problems are very good
Can anybody tell me why this code is giving RE in problem D. Link to solution: https://atcoder.jp/contests/abc346/submissions/51621300
Because your memory usage (3628612 KB) is greater than the memory limit (1024 MB). You probably run into bad_alloc
Can you tell why my code memory usage exceeds, as it is a simple dp solution.
I modified your submission into this Now it passes. The idea is to change
string
tostring&
in the function declaration.Ohh shit man silly error. Thanks for your help.
For D, I don't really get why this (http://atcoder.jp/contests/abc346/editorial/9651) is a correct solution. I don't understand how the answer is computed. I thought that if n is even, then the series first character must be different than the last character, so ans = min(ans, l0[i] + g1[i]) and ans = min(ans, l1[i] + g0[i]). If n is odd then the first and last characters are the same so ans = min(ans, l0[i] + g0[i]) and ans = min(ans, l1[i], g1[i]).
However I see that doesn't matter for the solution. I'm confused — can anybody explain it to me?
So, if you see, if you fix value of s[1], then you can predict value of s[n] too. Based on whether N is odd or even.
Now, for each i you can precompute pref0[i] to be minimum cost to make first i chars alternating 01s starting from s[1]=0
There are 4 pairs (pref0[i],suf0[i]) , (pref1[i],suf1[i]), (pref1[i],suf0[i]) and (pref0[i],suf1[i]), based on value of N, only 2 are valid.
Thank you! Everything is clear to me until the last step. For the last point, isn't the validity of a pair out of the 4 based on whether n is even or odd? What i am saying is that if n is even, then (pref0, suf0) and (pref1, suf1) are valid, and if n is odd, then (pref0, suf1) and (pref1, suf0) are valid. What am i missing here?
Yes, thats the correct interpretation of the last line.
can i do problem G by taking number of elements to right until not finding current element and left and add to result like res+=l*r is this wrong approach please help me
You end up with lots of duplicate pairs. Think about a simple case [3, 4], you gonna count pair (1, 2) twice according to what you say.
Thanks
When will the test data for ABC344/ABC345/ABC346 be uploaded? I need it now, thanks!
There is something wrong with my submission on F. Can anyone help me? Many thanks. https://atcoder.jp/contests/abc346/submissions/51648515
Correct answer is 1.
My problem has been solved now. Thank you for your reply.
This solution fails on only one test case could someone help? https://atcoder.jp/contests/abc346/submissions/51666225
Take a look at Ticket 17443 from CF Stress for a counter example.
overflow :3 , Thank you very much!