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

Автор maroonrk, история, 4 года назад, По-английски

We will hold AtCoder Regular Contest 150.

The point values will be 300-500-500-700-800-1000.

We are looking forward to your participation!

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

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

Hope to solve three problems. And not get too happy just by solving two problems.

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

Hope you all have a good time in this competition!

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

I just wonder who aaa1a is.

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

Couldn't solve any :( I think A was too case-heavy for me

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

    A was really straightforward. Very little case work. (Actually 0).

    #include<bits/stdc++.h>
    
    void solve() {
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int tcnt0 = count(all(s), '0');
        int tcnt1 = count(all(s), '1');
        int cnt0 = 0, cnt1 = 0;
        for (int i = 0; i < k - 1; i++) {
            if (s[i] == '0') cnt0++;
            else if (s[i] == '1') cnt1++;
        }
        int ans = 0;
        for (int i = k - 1; i < n; i++) {
            if (s[i] == '0') cnt0++;
            else if (s[i] == '1') cnt1++;
            if (cnt0 == 0 && cnt1 == tcnt1) {
                ans++;
            }
            if (s[i - k + 1] == '0') cnt0--;
            else if (s[i - k + 1] == '1') cnt1--;
        }
        cout << (ans == 1 ? yes : no) << '\n';
    }
    
    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int t = 1;
        cin >> t;
        while (t--) {
            solve();
        }
        return 0;
    }
    
»
4 года назад, скрыть # |
 
Проголосовать: нравится +26 Проголосовать: не нравится

Is it only me that feels that Atcoder problems are more simple and interesting (even hard ones), as compared to codeforces.

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

I don't understand why this code for A doesn't work. I believe I have the same idea as the editorial, although I implemented it badly, or maybe did something wrong, but I can't find it even after searching for an hour. Could someone help me out?

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

This is the code for starr(https://atcoder.jp/contests/arc150/submissions/35550331), which I think is TLE.

#include <iostream>
using namespace std;
#define int long long
signed main(){
    int t,a,b,i;
    cin>>t;
    while(t--){
        cin>>a>>b;
        if(a>=b) cout<<a-b<<"\n";
        else{
            if(b%a==0) puts("0");
            else{
                int now=b/a,mi=b-a;
                mi=min((b/a+1)*a-b,mi);
                //b/(mi+a-1)
                for(i=now;i>=1;i--){  //i是倍数
                    int x=b/i+(b%i!=0);
                    //cout<<x<<" "<<x*i<<" "<<a<<endl;
                    mi=min(mi,x-a+x*i-b);
                }
                cout<<mi<<endl;
            }
        }
    }
}
»
4 года назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +8 Проголосовать: не нравится

Can problem — A Continuous 1 https://atcoder.jp/contests/arc150/tasks/arc150_a

be solved using DP ??

I tried dp but it couldn't get correct solution .

My idea :

Each '?'has 2 options to be replaced using '0' or '1' .

I formed this recursive logic

idx -> index , leftOne == K — alreadyPresentOne '1'

I'm asking from isPossible() , whether it's possible to have K consecutive 1's And for each True I increment counter , If counter > 1 return False.


bool isPossible(int idx, int leftOne) { if (idx >= n && leftOne != 0) return 0; if (leftOne == 0) { //Check if K consecutive 1' possible and ++counter if (pfxSum[i] == tar) { ++counter; return true; } } return false; } while (idx < n && s[idx] != '?') { ++idx; } bool way1 = false, way2 = false; // if (dp[leftOne][idx] != -1) // return dp[leftOne][idx]; if (s[idx] == '?') { s[idx] = '1'; way1 = isPossible(idx + 1, leftOne - 1); s[idx] = '0'; way2 = isPossible(idx + 1, leftOne); s[idx] = '?'; } return (way1 || way2); }

But when I turned it into dp[index][leftOne] , I couldn't do I realise it's because let say I've 00?1???10? if at one instance like 001111010? dp[7][0] == No but then for 0001111100 dp[7][0] == Yes

Please verify if it's dp solvable or not ??

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

I think my solution to problem C is a little weird, and I am not sure if it is correct (although get AC).

I use normal bfs, starting from node-1, but with k stages, where k is just the input in the statement. For each stage, we keep visiting all the unvisited nodes until we meet nodes-x, where a[x]=b[stage]. During the process, if node-n has been visited, then the answer is no, otherwise is yes.

By the way, problem B uses the sqrt-technique, which is somehow similar to problem B in ARC139. I feel very lucky that I realize this quickly.

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

How I "solved" B:

  • First, notice that ans is at most min(b-a,a) so you can bruteforce for all x<=1 mil and this handles all cases with a<=1mil.

  • For the remaining cases(a>1mil): Suppose b+y = z(a+x), bruteforce for all z <= b/a and y<=b/a. Both loops are <= 1000 runs

  • I think this is WA solution but weak tests. If it happens to be correct, can anyone show proof?

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

In editorial of problem D — tester's solution: "Not only bad vertices but also good vertices can be chosen.". Why doesn't that change the result?

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

    The outcome of the random variable $$$X_v$$$ depends on status of the parents of $$$v$$$. That is, it just needs to 'keep track' of the parents to know when $$$v$$$ has become good and it needs to stop performing operations. This intuition explains why we don't care about the operations which pick something apart from $$$v$$$ and its parents. Those operations neither change the state of $$$v$$$'s parents, nor do they directly change the value of the random variable (which would only be affected when we pick precisely $$$v$$$).

    A similar argument holds for not caring about whether we pick good or bad vertices. Even if we pick a good vertex, it was already coloured black from earlier. So the status of none of the parents change. We know we didn't pick $$$v$$$ itself, since the process would have already stopped if $$$v$$$ was good beforehand. This operation doesn't affect the value of the random variable as well. And so we're free to consider them as valid moves.

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

I was lost while reading editorial of B. Someone save me please.

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

    We want $$$B+Y$$$ to be a multiple of $$$A+X$$$, i.e., $$$B+Y = k(A+X)$$$ for some positive integer $$$k$$$.

    If someone told you what $$$k$$$ you need to use, then part 1 of the editorial tells you how to find $$$X$$$ and $$$Y$$$ such that $$$X+Y$$$ is smallest. We have, $$$Y = kX+kA-B$$$ and $$$X+Y = (k+1)X+kA-B$$$. To minimize $$$X+Y$$$ is then same is to minimize $$$X$$$, because $$$k$$$, $$$A$$$, and $$$B$$$ are fixed. We choose smallest $$$X$$$ such that $$$Y \ge 0$$$ (recall $$$Y = kX+kA-B$$$). This value is $$$\max(0, \lfloor\frac{B-1}{k}\rfloor + 1 -A)$$$ (convince yourself of this).

    Part 2 then tells you that for $$$k \le \sqrt{B})$$$ you can just compute this value, and the number of different values of $$$\lfloor\frac{B-1}{k}$$$ for $$$k \gt \sqrt{B}$$$ is at most $$$\sqrt{B}$$$. For example, if $$$B = 101$$$, then $$$\lfloor\frac{B-1}{k}\rfloor$$$ can take values $$$9, 8, 7, 6, 5, 4, 3, 2, 1$$$ if $$$k\ge 11$$$. So you compute minimizing $$$X$$$ using $$$k = 1, 2, \ldots, \sqrt{B}$$$ first then compute minimizing $$$X$$$ using $$$\lfloor\frac{B-1}{k}\rfloor = 1, 2, \ldots, \sqrt{B}$$$. (Maybe try 2 or 3 more values if I am missing some constants.)

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

    I also couldn't understand the editorial of B. Then I looked at more editorials and found a better explanation from the official video editorial:

    For B + Y = k(A+X), there are two approaches to find X + Y:

    • Approach 1: Enumerate X from 0 to A-1, we can get a value of X + Y for each case and keep the minimum.
    • Approach 2: Enumerate k from 1 to B/A, we can get a value of X + Y for each case and keep the minimum.

    Note the range of X and k, when A is extremely small or extremely large, either Approach 1 or Approach 2 can be very slow. Therefore, pick a value of sqrt(B) to determine to only use the faster of the 2 approaches.

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

      Much cleaner! Just to add a tiny elaboration: if $$$A \le \sqrt{B}$$$, then Approach 1 uses $$$\le\sqrt{B}$$$ iterations, and when $$$A \gt \sqrt{B}$$$, Approach 2 uses at most $$$B/A \le\sqrt{B}$$$ iterations.

      Edit: Actually, reasoning for why Approach 2 only checks until $$$B/A$$$ is not clear to me.

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

In problem B, he has not used the $$$\sqrt{N}$$$ algorithm but something else. Can someone explain his code please

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

I have a small confusion regarding simple path

Simple path doesn't mean it is the shortest path right , it means path which doesnot contains two or more same vertices

Then in the sample test case 2 of problem C why we are not considering path (1,2,3,4,5) ?