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

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

We will hold Toyota Programming Contest 2023#7(AtCoder Beginner Contest 328).

We are looking forward to your participation!

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

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

Hello!

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

Hello everyone! Is everyone ready to contest? I wish luck to everyone! :)

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

I wish everyone luck in the game

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

Wish everyone luck!

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

Hello!

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

Good Luck everyone

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

Good Luck!

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

Good luck!

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

Good luck!

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

Is AtCoder down again? Why is it always failing during contests?

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

Good luck!

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

Problem F:

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

for problem E i did the black box strategy since i don't know the algorithm, I copied and pasted solution from GFG with some modification of course

why does it give a wrong answer for testCase 3?

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

Nice problems, I liked solving D, E and F today.

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

In problem G, were $$$O(2^n \cdot n^2)$$$ solutions intended to pass if optimized well?

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

    No it will get MLE :(

    And the memory limit is intentionally set to $$$512\operatorname{MB}$$$, since you need long long it will cost $$$22\times2^{22}\times8\operatorname{B}=704\operatorname{MB}$$$.

    UPD: Ohhhhhhhhhhhh I optimized the space (halved it) and got AC

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

      You can reduce space complexity to O(2^n) by solving the dp in increasing order of popcount and only allocating space for current and next popcount.

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

        Alternatively, just maintain $$$dp_{mask}$$$ = min cost to take these elements from A and map them to a prefix of B. Then just take a consecutive subarray of elements without a split $$$[i, j]$$$ in one shot using an $$$O(n ^ 2)$$$ loop.

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

      That's because you're using $$$O(2^n \cdot n)$$$ memory. On the largest input this will use around 700 MB, but the memory limit is only 512 MB.

      But you can notice that some of the $$$2^n \cdot n$$$ states aren't valid, and the number of valid states is just small enough ($$$46137344$$$ on max test) to fit in the memory limit. In my code I only allocate memory for valid states and it gets AC. Submission

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

    I don't think so.
    My $$$O(2^n \cdot n)$$$ soln took 0.9/2.8s time.
    $$$O(2^n \cdot n^2)$$$ should get TLE.

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

      Nevermind mine turned out to be O(n * 2^n)...

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

      My $$$O(2^n \cdot n^2)$$$ soln passed in 0.4s. The key part being that it only actually uses ~$$$8 \cdot 10^7$$$ ops in practice due to not all possible values of $$$1 \leq i \leq j \leq n$$$ being used in a mask.

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

        The key part of your solution is that it's actually $$$O(2^n \cdot n)$$$, not $$$O(2^n \cdot n^2)$$$.

        For each of the $$$2^n$$$ bitmasks and for each subarray $$$[i, j]$$$, your solution does calculations for this subarray if all of the corresponding bits of this subarray are $$$0$$$.

        For a subarray of length $$$k$$$, there are $$$2^{n-k}$$$ bitmasks where all bits of this subarray are $$$0$$$. There are also $$$(n + 1 - k)$$$ subarrays of length $$$k$$$.

        This means that the number of operations your code does is on the order of

        $$$\displaystyle\sum_{k=1}^n 2^{n-k}(n+1-k)$$$

        $$$=\displaystyle\sum_{k=1}^n 2^{k-1}\cdot k$$$

        $$$\le \displaystyle\sum_{k=1}^n 2^{k-1}\cdot n$$$

        $$$= n\displaystyle\sum_{k=1}^n 2^{k-1}$$$

        $$$= n\displaystyle\sum_{k=0}^{n-1} 2^k$$$

        $$$= n(2^n-1)$$$

        $$$\subseteq O(2^n \cdot n)$$$

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

For problem E, I tried using a Dijkstra to find the MST. To my concern, the implementation is well written. Why didn't it work?

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

Please can anyone explain how to solve G? my n*2^n method got WA, thanks a lot.

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

E — Modulo MST and i choose kruskal to solve it. why it failed on case 3? please help me

Your code here...
#include<bits/stdc++.h>
#define cout3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define int  long long
using namespace std;
const int maxn=2e5 + 10;
int n,m,k,f[maxn],ans=0;

struct Edge{
    int u,v,w;
}e[maxn];

int find(int x){
    if(f[x] == x) return x;
    return f[x]=find(f[x]);
}

bool cmp(Edge x,Edge y){
    return x.w < y.w;
}
signed main(){
    // freopen("in.txt","r",stdin);
    cin >> n >> m >> k; 
    for(int i=1;i <= n;i++) f[i]=i;
    for(int i=0;i < m;i++) cin >> e[i].u >> e[i].v >> e[i].w,e[i].w%=k;
    sort(e,e + m,cmp);
    for(int i=0;i < m;i++){
        int fv=find(e[i].v),fu=find(e[i].u);
        if(fv == fu) continue;
        f[fv]=fu;
        // cout3(e[i].u,e[i].v,e[i].w);
        ans+=e[i].w;
        ans%=k;
    }
    cout << ans % k;
    return 0;
}
»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

In editorial of E, how is he enumerating the spanning trees?

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

So, origin problems:

Dabc307D Mismatched Parentheses

Because of some problems, it isn't completed.

May update.

Very special things:

In sometimes in the contest, I'd ever solved problem E and don't solve problem D!

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

Porblem F is very great, and I have seldom solved a problem which uses weighted dsu (this may be the second time). I learned a lot from this problem, thank you, atcoder team.

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

    Can you please explain your dsu approach?

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

      In fact, I didn't solve it during the contest, and I also learned this from the editorial. My dsu approach is just the same as the one mentioned in the editorial. Different from the simple dsu, which only records whether two nodes are "connected", this weighted dsu would maintain another variable which stores the "relation" from each node to its ancestor node. I think you can search this topic on the Internet, or, blogs at codeforces. I think there have been several blogs talking about this at codeforces.

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

Good problems.

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

Problem E can be hardcoded :) submission

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

Problem F is good, worth solving.

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

Why in B they didn't take 12 December???

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

    Day j of month i is said to have a repdigit date if and only if one can represent both i and j using just one kind of digit in decimal notation. For example, December 12th is not a repdigit date, as i = 12 and j = 12, requiring two kinds of digit (1 and 2) to represent them.

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

Is there a solution for problem D without the use of stack?

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

E = Brute Force. Do you see the $$$2 \lt =n \lt =8$$$?

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

HELP, Can anyone explain the F solution? Actually, What are we storing in the weight array?