Блог пользователя chokudai

Автор chokudai, история, 6 лет назад, По-английски

We will hold AtCoder Beginner Contest 161.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +70
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I wish it will be a perfect contest!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In Problem F
For N = 6
When K = 3 : 6 -> 2 -> 1
Why K = 3 is not considered in first sample?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Do you have a smooth network today?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Why does this solution fail E?

Code

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

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится -9 Проголосовать: не нравится

    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:

    #include <bits/stdc++.h>
    #define int long long
     
    using namespace std;
     
    signed main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n, k, c;
        string s;
        cin >> n >> k >> c >> s;
        int dpl[n + 1], dpr[n + 1];
        dpl[0] = 0;
        dpr[0] = 0;
        int last = -10000000;
        for (int i = 1; i <= n; ++i) {
            if (s[i - 1] == 'x') dpl[i] = dpl[i - 1];
            else if (last + c < i) {
                last = i;
                dpl[i] = dpl[i - 1] + 1;
            }
            else dpl[i] = dpl[i - 1];
        }
        last = -10000000;
        for (int i = 1; i <= n; ++i) {
            if (s[n - i] == 'x') dpr[i] = dpr[i - 1];
            else if (last + c < i) {
                last = i;
                dpr[i] = dpr[i - 1] + 1;
            }
            else dpr[i] = dpr[i - 1];
        }
        //for (int i = 0; i <= n; ++i) cout << dpr[i] << " ";
        for (int i = 0; i < n; ++i) {
            int left = i;
            int right = n - i - 1;
            if (s[i] == 'o' && dpl[left] + dpr[right] < k && dpl[left] + dpr[right] + 1 >= k) cout << i + 1 << endl;
        }
        return 0;
    }
    
  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +8 Проголосовать: не нравится

    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

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Maybe the hardest thing to encounter image

    Can anyone check why this fails in one test case? https://atcoder.jp/contests/abc161/submissions/17260017

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think the difficulty gap from C to D is way more than expected

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

Video tutorials + Screencast

Screencast

Video Editorials

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

I think F is easier than D;

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can somebody explain me logic behind problem F? I only can guess that n = (ak + 1) * b or n = ak + 1.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    Solution to $$$F$$$:

    If $$$N=2$$$, the answer is $$$1$$$.

    Otherwise, let's define the function $$$f(x, y)$$$ like this:

    bool f(long long x, long long y)
    {
        while(x%y==0)
        {
            x/=y;
        }
        return x%y==1;
    }
    

    Now for all $$$i$$$ $$$(i \gt 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$$$.

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +4 Проголосовать: не нравится

    $$$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

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Can you please explain it with more details?

      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        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$$$.

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://ide.codingblocks.com/s/205523

Why is this giving WA in B ?

»
6 лет назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone tell me where my code for F is wrong. Only 6 out of 25 test cases were wrong.

Code
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

In D I used binary search + digit dp. It took me a lot of time to implement that :/// solution link

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What am I missing for D? 100000 case doesn't work.

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

        int k = Integer.parseInt(br.readLine());

        HashSet<Long> set = new HashSet<>();
        LinkedList<Long> q = new LinkedList<>();
        for (long i = 1; i <= 9; i++) {
            q.add(i);
            set.add(i);
        }

        if (k <= 9) {
            pw.println(k);
            pw.close();
            return;
        }

        while (!q.isEmpty()) {
            long head = q.poll();
            for (long i = head % 10 - 1; i <= head % 10 + 1; i++) {
                if (i < 0) continue;

                long val = head * 10 + i;
                if (set.contains(val)) continue;

                set.add(val);
                q.add(val);

                if (set.size() == k) {
                    pw.println(val);
                    pw.close();
                    return;
                }
            }
        }

        pw.close();
    }
}
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone describe how to solve D? Was it dp digits?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is wrong with the following code for problem B?

    int n,m;
    cin>>n>>m;
    int tot = 0;
    vector<int> arr(n,0);
    for(int i=0;i<n;i++) {
    	cin>>arr[i];
    	tot+=arr[i];
    }
    sort(arr.rbegin(),arr.rend());
    int req=tot/(4*m);
    int cnt = 0;
    for(int i=0;i<n && cnt<m;i++) {
    	if(arr[i]>=req) {
    		cnt++;
    	} else break;
    }
    if(cnt>=m) cout<<"Yes";
    else cout<<"No";
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think this contest is more difficult than before.

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
#include<bits/stdc++.h>
using namespace std;

int main(){
  long long n,k;
  cin>>n>>k;
  long long N=n;
  long long mn=1000000000000000000;
     while(n>=0){
        mn=min(n,mn);
        if(n<k){
            n=k-n;
        }
        else{
            n=n-k;
        }
        if(n==mn){
        mn=min(n,mn);
            break;
        }
     }
     cout<<mn;

   return 0;
       }

i was getting tle. Can anyone help me ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

So,how to solve the problem D?

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +4 Проголосовать: не нравится

    If you were to generate all numbers, it'd be something like this:

    vector<long long> num;
    void brute(int i, int last, long long cur){
        if(i == 0) return;
        num.push_back(cur);
        if(last > 0) brute(i-1, last-1, cur * 10 + last - 1);
        if(last < 9) brute(i-1, last+1, cur * 10 + last + 1);
        brute(i-1, last, cur * 10 + last);
    }
    

    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.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    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.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

So how to solve E?

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +8 Проголосовать: не нравится

    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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Please atcoder! can you make english editorial.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

can anyone explain the d part and what is written in the editorial of d in japanese

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 3  
    Проголосовать: нравится +4 Проголосовать: не нравится

    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.

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    The same idea:

    Code
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It's harder to understand the editorial than to understand the problem statement. (Since the editorial is in Japanese ! )

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

can anyone plz explain the logic behind E??

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +7 Проголосовать: не нравится

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

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

Supplementary editorial and sample codes for last 4 problems AtCoder ABC 161

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

why this code is giving TLE for question F

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll func(ll n,ll x)
{
    while(n%x==0)
        n/=x;
    if(n%x==1)
        return 1;
    else return 0;
}
int main()
{
	ll t;
	t=1;
	while(t--)
    {
        ll n;
        cin>>n;
        ll s=0;
        for(int i=2;i*i<=(n-1);i++)
        {
            if((n-1)%i==0)
            {
                s++;
                if((n-1)/i != i)
                    s++;
            }
        }
        ll c=0;
        for(int i=2;i*i<=n;i++)
        {
            if(n%i==0){
                c+=func(n,i);
            if(n/i != i)
                c+=func(n,n/i);
            }
        }
        cout<<c+s+2;
    }
}

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://atcoder.jp/contests/abc161/submissions/11592729

what is the problem in this submission for problem C?