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

Автор atcoder_official, история, 16 месяцев назад, По-английски

We will hold AtCoder Beginner Contest 408.

We are looking forward to your participation!

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

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

why competitive companion is not working for atcoder problems?????

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

I wonder if the writers play Genshin? BCG are all repeated question

B

G

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

Another time

Spoiler

, and another time I couldn't implement at time because I didn't have it on my lib

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

Problem $$$E$$$ seems really standard/common but I'm not able to solve it :(

Is it Dijkstra like d[u][x] = smallest mask with x set bits with which we can reach node u, starting from node n? I got 9 testcases WA with this approach.

Edit: I just read the editorial. What an amazing problem!

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

Why did you kill $$$\mathcal{O}(\log ^2 X)$$$ on G? Going from $$$\mathcal{O}(\log ^2 X)$$$ to $$$\mathcal{O}(\log X)$$$ is only an improvement in specific details of the algorithm, yet not any meaningful improvement.

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

can anyone explain problem E i made the distance vector like dist[node][j] it is reprsenting the minimum distance to reach this node with the bit set at position j it is giving wrong please explain i have attatched the code

~~~~~ void solve(){ int n,m; cin>>n>>m; vector<pair<int,int>>adj[n+1]; for(int i=0;i<m;i++){ int u,v,w; cin>>u>>v>>w; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } // vectorleastbitset(n+1,32);

priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;

q.push({0,1});
vector<vector<int>>dist(n+1,vector<int>(31,LLONG_MAX));
for(int i=0;i<=30;i++){
    dist[1][i]=0;
}


while(!q.empty()){

    int wt=q.top().first;
    int node=q.top().second;
    q.pop();
    bool todrop=true;
    for(int i=29;i>=0;i--){
        if((1LL<<i)&wt){
            if(dist[node][i+1]==wt){
                todrop=false;
                break;
            }
        }
    }
    if(wt!=0){
        if(todrop) continue;
    }

    for(auto it:adj[node]){
        int val=wt|it.second;
        if(val==0){
            dist[it.first][0]=0;
            q.push({val,it.first});
        }
        else{
            bool topush=false;
            for(int i=29;i>=0;i--){
                if((1LL<<i)&val){
                    if(dist[it.first][i+1]>val){
                        dist[it.first][i+1]=val;
                        topush=true;
                    }
                }
            }
            if(topush){
                q.push({val,it.first});
            }
        }

    }
}
int ans=LLONG_MAX;
for(int i=0;i<31;i++){
    ans=min(ans,dist[n][i]);
}
cout<<ans<<endl;

} ~~~~~

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

    Suppose there are five bits. You are able to arrive node u with a value (01111)2 and (10000)2.

    And then we suppose it is neccesary to add (1<<4) to the answer if we want to arrive node n, than this dijkstra fails to find the best solution because it chooses (01111)2 rather than (10000)2 to arrive node u.

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

I saw the G of today's competition a long time ago. It's a very classic question. However, did atcoder not realize this at all and keep it? I'd like to ask the question setter: Do you play Genshin Impact?

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

I don't know how to solve the problem D!!!! I have failed on problem for 7 times!!!

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

    Using kadane's algorithm, try to pick as many 1 as you can, final ans would be total 1 — max 1s that you could pick (this is 1 — 0 continous count)

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

      how did you get this intuition? can you please explain your thought process behind reaching to this solution. thanks in advance.

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

        The question asks for the min number of ops (1 -> 0, 0 -> 1) such that after the ops the array has at most one continous 1s subarray.

        we have 2 options for each existing 1, either let that 1 be 1 in the final answer or else convert it to 0, now to minimize the number of ops, we would want to retain the maximum numbers of 1s.

        In order to retain max number of 1s we have to pick a subarray which has max number of 1s if continous if not then the cost to convert 0 -> 1 which occur in between should compensate against the additional 1s gained.

        eg 11100111, here it would be a better deal to convert 00 -> 11 we will end up do 2 ops but would get 3 1s in return hence profit, so we can calculate whats the max 1s we can retain using kadane algorithm.

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

    DP

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

How to solve the E problem? can someone help?

Seemed like some sort of Dijkstras, but not sure how to do it.

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

could anyone explain D ?

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

    this is how I did it

    suppose the answer is the range l to r

    so flips required = one outside + zero inside

    so we want min ( 1o + 0i) ... where o = outside, i = inside the range l to r

    min (1o + 0i) = min( (total 1) - 1i + 0i) = (total 1) + min( -1i + 0i) = (total 1) - max(1i - 0i)

    so we want to maximize count of 1 - count of 0 inside the range

    so if we replace every 0 with -1 .. then we just need to find maximum sum subarray .. which can be done in O(n) using kadane ( DP storing ans ending at a particular index)

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

downvoted. g is an already-existing problem... AGAIN.

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

https://atcoder.jp/contests/abc408/submissions/66352331

hack data

3 5 1 2 16 1 2 2 1 2 3 1 2 4 2 3 4

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

Please give this contest a down vote.It's full of repeat problems.

Playing Genshin cause it.