We will hold AtCoder Beginner Contest 161.
- Contest URL: https://atcoder.jp/contests/abc161
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20200404T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 6
- Writer: chokudai, evima, kyopro_friends, latte0119, namonakiacc, sheyasutaka, EnumerativeCombinatorics, YoshikaMiyafuji
- Rated range: ~ 1999
The point values will be 100-200-300-400-500-600.
We are looking forward to your participation!
I wish it will be a perfect contest!
Today's Internet is not smooth
In Problem F
For N = 6
When K = 3 : 6 -> 2 -> 1
Why K = 3 is not considered in first sample?
When 3 divides 6 it changes N to N/k which is 2 and N-K,i.e., 2-3 is equal to -1 and not 1. :)
for k=3
n = 6
1> 6%3==0: n = 6/3=2
2> 2%3!=0: n = 2-3=-1
it's wrong
Ok, Thanks I wrongly interpreted the question, I thought that we can choose different K at each step while reducing N.
Hmm, everyone is pointing out wrongly... If you choose $$$K = 3$$$, performing one operation results in $$$2$$$, which is less than K, so you don't have to consider operations one more time :)
Do you have a smooth network today?
Why does this solution fail E?
If max amount of work is greater than k then the answer is empty.
Else let bottleneck day be the only day on which max amount of work is equal to j(say),search for bottleneck, it would be part of the answer, now search for bottleneck again starting from index (currentbottleneck+c+1) and repeat till i=n-1
I solved E doing dpl[n + 1] and dpr[n + 1] — the max days we can work in 0...i for dpl and i...n dpr. So i will be in the answer if dp[i] + dp[n — i — 1] < k and dp[i] + dp[n — i — 1] + 1 == k and
s[i] == '0'.Sorry for my poor English.
Code:
You need an else block for when indices.size()!=1: In this case, the best strategy (i.e. causes the least forced days) is to work on the earliest day $$$d^*$$$ inside indices{}, because if a future day is forced when using $$$d^*$$$ then it is also forced for any other $$$d$$$ inside indices{}, but not necessarily the other way around. After you select $$$d^*$$$, you should increment the index appropriately.
For instance suppose you have 4 o's in a row, where the first and second have maxwork=2, and the third and fourth have maxwork=1. Then assume you work on the day with the first o. This might disqualify the 3rd o, making the 4th o forced. So you need a condition similar to your index=c+1+index1, except assuming you work on the earliest day $$$d^*$$$.
I think something like "oooxo" with k=2, c=2 should exhibit this problem- you'll have maxwork = 2, 2, 1, 1, etc.
Mine to compare (btw linear time with a stack instead of a set is possible) https://atcoder.jp/contests/abc161/submissions/11538625
Thank you very much :D
Moved the
index=c+1+index1;
part outside if statement and it worked :DMaybe the hardest thing to encounter
Can anyone check why this fails in one test case? https://atcoder.jp/contests/abc161/submissions/17260017
I think the difficulty gap from C to D is way more than expected
D is bruteforce recursion, and I feel F is also much easier this time.
You can also use DP
Solution
D is not hard, just dfs.
How you used dfs in it?
I just generated up to 10^5 Lunlun Numbers and output the kth
Video tutorials + Screencast
Screencast
Video Editorials
I think F is easier than D;
With D a brute force works, just maintain the lunlun numbers as an array, and increment i times. That is fairly simple compared to F.
Submission
Can you explain your logic please !
We store the digits of the number in an array as if written down on paper.
Incrementation works just like that, we increment the lowest significant digit. If it runs out of scope (higest possible number), then we increment the one at one position higher, and use the lowest possible number for the digits at the lower positions.
Can somebody explain me logic behind problem F? I only can guess that n = (ak + 1) * b or n = ak + 1.
Solution to $$$F$$$:
If $$$N=2$$$, the answer is $$$1$$$.
Otherwise, let's define the function $$$f(x, y)$$$ like this:
Now for all $$$i$$$ $$$(i>1)$$$ which is the factor of $$$N$$$, add $$$f(N, i)$$$. Let's define this sum as $$$S$$$, and the number of factors of (N-1) as $$$T$$$. The answer is $$$S + T$$$.
$$$n$$$ can be of the form $$$k^p$$$ or $$$k^p(km+1)$$$. So we can loop over $$$\sqrt{n}$$$ values to check such $$$k$$$. Here
Can you please explain it with more details?
Umm I mean suppose you have reached $$$1$$$ then either you reached it by dividing some other number by $$$k$$$ or adding $$$k$$$.
Now just follow the question's operations. Note that as soon as our number is not divisible by $$$k$$$ then we may only subtract $$$k$$$. So in the first case in above paragraph, it must be that number is $$$k^p$$$. In second case, we may add any number of $$$k$$$, and after that multiply by $$$k$$$ any number of times, so that following questions sequence of operations always reduces it to $$$1$$$.
Can anyone reason out why adding codes for compiler optimization gives RTE ? I wasted a lot of time and attempts over it. RTE AC chokudai ?
https://stackoverflow.com/questions/2722302/can-compiler-optimization-introduce-bugs
https://ide.codingblocks.com/s/205523
Why is this giving WA in B ?
it should be ceil(sum/(4.0*(double)m)). you are meant to round it up to fit the requirement
you are dividing sum by 4*m and both of them are int, so there division gave you a rounded down int. suppose sum/(4*m) is 96.5, your code will convert it to 96 and then include all the 96s in the array which shouldn't be include as 96<96.5 . use double while dividing and then use ceil function.
Line 23:
if(v[i]>=sum/(4*m))
, this does integer division as both sum and m are integers.The correct way would have been to store it in a double and then compare.
Cast integers to doubles where you are doing division and comparison
Better use multiplication on the left side instead of divison on the right.
Change
if(v[i]>=sum/(4*m))
toif(4*m*v[i]>=sum)
.Could someone tell me where my code for F is wrong. Only 6 out of 25 test cases were wrong.
public class F { private static long n; private static int[] a;
}
if i is a factor then n/i is also a factor.U missed to check for n/i in the first for loop.
You are printing twice when n=2
I accidently removed return in the if condition while debugging.
In D I used binary search + digit dp. It took me a lot of time to implement that :/// solution link
Can you explain please what dp[12][N][2][2] in your code means?
You may check the digit Dp article if you don't know about it.
Digit DP
yeah sure,
first dim means — the last digit that is used
second dim means — the length of number iterated
third means — the lower limit is fixed or not (this one is not required as lower limit is always one)
fourth one — if upper limit is fixed or not
Wow, Thank you!
Same here. D was a bit tough for me while F was much easier. It took me 25 minutes to solve D with BS+digitdp and just 7 minutes in F.
What am I missing for D? 100000 case doesn't work.
Never mind, I figured it out. When the last digit is 9, the queue puts in a 0, bc (9 + 1) % 10 = 0
Can someone describe how to solve D? Was it dp digits?
I solved it using bfs. Here is my solution
I used simple BFS.
Thank you bro
I did it using simple bfs.
link to submission
You can solve with bruteforce, just store Lunlun numbers in an array.
Then check the last digit of i'th entry, let it be x. Then for next position, you can have digit -> x-1, x and x + 1.
For example: Initial array : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Consider you are at 1 -> 10 , 11, 12. Then increase the pointer after you try all consecutive of current entry.
Now do same for 2-> 21, 22, 23.
and keep adding them in the array. You can implement it recursively as well as iteratively.
Iterative
BFS can solve the problem.
What is wrong with the following code for problem B?
Try making req into a double:
double req=(double)(tot)/(4*m);
I think this contest is more difficult than before.
i was getting tle. Can anyone help me ?
For small k and big n the loop will run n/k times, wich then is to slow. You can speed this up by using mod operations.
oh yes. thanks. i tried to make both conditions using mod but the k>n condition was giving error. But why? can you please explain ?
I think there are a lot of possible implementations. The basic aproach is the same for all: For big $$$n$$$ and small $$$k$$$ the loop is shortened by removing a multiple of $$$k$$$ in one step.
My Submission
So,how to solve the problem D?
If you were to generate all numbers, it'd be something like this:
Where $$$i$$$ is the maximum number of digits, $$$last$$$ is the last digit you used and $$$cur$$$ is your current number.
Then, you can use nth_element or sort to get $$$k-1$$$ smallest.
But why does this work? Well since there are only 3 transitions, complexity would be $$$O(3^D)$$$ where D is the maximum number of digits. Turns out answer will have not more than 12 digits so you can just brute force it =p.
Thank you. I understand it
You can approach that problem by using backtracking. Let's say you have a lunlun number x, you can find another lunlun number by taking the last digit of x which is d = (x%10) and appending d, d+1, d-1 to x. Then you keep doing the same on the new lun lun number. Also you have to keep in mind that initially you have start with all the single digit numbers. You can imagine the tree as 0 at the top and the root node, the from that emerges 9 branches to 1, 2, 3, 4, 5, 6, 7, 8, 9. Then from each one of them will emerge at most 3 branch. Like from 2 we will have 21, 22, 23. And so on.
Thanks,bro~
So how to solve E?
Let's define dpl[i] as the max number of days that we can work in first i days, and define dpr[j] as the max number of days that we can work in last j day. The size of both arrays is n + 1. We can precalculate dpl and dpr greedy, base: dpl[0] = 0, dpr[0] = 0, last = -inf. Then iterate from left to right, keeping last as last day when he worked. Same for dpr.
If day i is in the answer, then s[i] == 'o'(Im counting days from 0 to n — 1) and dpl[i] + dpr[n — i — 1] < k and dpl[i] + dpr[n — i — 1] + 1 == k(may be its useless condition). Time complexy: O(n) Code:
https://atcoder.jp/contests/abc161/submissions/11534466
Please atcoder! can you make english editorial.
Or if someone just translates the existing one to English.
can anyone explain the d part and what is written in the editorial of d in japanese
This problem can be solved efficiently using Queue.
Prepare one Queue and Enqueue 1, 2, ..., 9 in order. Then do the following K times:
Dequeue the Queue. Let x be the extracted element.
Let d = x mod 10.
if d = 0. Enqueue 10x, 10x+1.
if d = 9. Enqueue 10x + 8, 10x + 9;
else Enqueue 10x + d-1, 10x + d, 10x + d + 1.
Kth extracted element will be the answer.
Above is what you get if you translate the Japanese editorial for D.
The same idea:
It's harder to understand the editorial than to understand the problem statement. (Since the editorial is in Japanese ! )
can anyone plz explain the logic behind E??
https://codeforces.me/blog/entry/75551?#comment-597715 Great explanation ...
Find the earliest and latest day of the $$$i$$$-th working day. If for some $$$i$$$ they are the same, this is a day bound to work.
You can greedily iterate the days to find the earliest days. Also, reversely iterating the days gives the latest days.
Why "they are same" indicates this is a day bound to work? Can you explain it more detailedly?
Ohhhhhhh! I suddenly understand it,Thx.
Thank you very much !
My submission for problem 'D' is giving Runtime error on sample test cases on Atcoder but this code is working fine on Codeforces custom invocation.
I tried to cut-short the code to find my mistake but still, I can't find my mistake, Here is the link of a very short and clean code which should give WA but is giving RE instead. Can someone help me find the mistake in either of the code?
Edit: It got accepted when I removed lines 8 to 12 (pragma tags) but I am still unable to understand why including pragma tags is giving RE here
Supplementary editorial and sample codes for last 4 problems AtCoder ABC 161
why this code is giving TLE for question F
use long long for i instead of int
thanks but can u tell me why it was giving tle earlier
i*i becomes negative when overflowing so the for loop will become an infinite loop
I find a data that someone can not pass for Problem E 5 2 1 oxooo the result is empty,but someone will out 1
Whats wrong in this solution for problem 'Replacing integer' . I have even gone through editorial solution.Its same as mine.Whats wrong here..Please someone look at this
https://atcoder.jp/contests/abc161/submissions/11572033
Instead of dividing on the right you better multiplicate on the left side, to avoid rounding issues.
Will u please see my solution of E.My solution is same as editorial. but i dont understand what the hell is wrong here?? pls look at this.
thanks in advance
https://atcoder.jp/contests/abc161/submissions/11577640
I think the editorial means the size of array is K , here is My code ,the idea is the same with editorial.it's easy to understand ,hope it will help.
thanks sir, got my mistake
I did something similar as well. I sorted the reverse array and then compared,but still got WA at the same test case as you were getting earlier. Can you please tell me where am I going wrong : https://atcoder.jp/contests/abc161/submissions/11594352
https://atcoder.jp/contests/abc161/submissions/11592729
what is the problem in this submission for problem C?