Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

We will hold THIRD PROGRAMMING CONTEST 2023 ALGO(AtCoder Beginner Contest 318).

The point values will be 100-200-300-400-450-575-575-650.

We are looking forward to your participation!

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

»
11 месяцев назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

F score=G score?

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

You are right, but Genshin Impact is a new upgraded open world game adventure game independently developed by the official of MiHoYo. Mobile games originated in a world called "Tivat", where the chosen person is given the "Eye of God" to guide the power of the stars. We will play a mysterious character named "Traveler" who meets friends with different temperaments and different abilities in his free travel. We will defeat the strong enemy with them and find the separated family. In addition, we will gradually discover the truth behind the "Genshin Impact".

»
11 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

F seems to be hard this time.

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

Is there anyone from Hongfan NO.8 Middle School in China?

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

it 's worth to be expected

»
11 месяцев назад, # |
Rev. 3   Проголосовать: нравится -19 Проголосовать: не нравится

hai!

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

I used Bing Translation to translate the question, but the translation turned out to be strange. Who can tell me the Chinese Tranlation of Question B, please.

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

AtCoder people don't watch Japan's Basketball match? :D

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

damn my 1 hr goes away in just first two questions...

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

I only did three questions...

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

How can D be solved with Bitmasks?

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

    it can be solved by dp, here is the code

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

    $$$dp[mask]$$$ = maximum answer for graph on vertexes $$$i$$$ such that: $$$mask$$$ & ($$$1$$$ << $$$i$$$) = $$$true$$$. The solution is $$$O(n^2 \cdot 2^n)$$$

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

    Why not DFS with a tiny cut?

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

    Here's the dp with bitmask- Code

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

    It can be solved by $$$O(n!)$$$ brute-force with a bitmask memorization either. Its time complexity is $$$O(2^n)$$$ .

    Here's the code.

    #include<iostream>
    using namespace std;
    using ll=long long;
    int n;
    ll gr[20][20],res,mr[1<<18];
    bool vis[20];
    ll dfs(int dep,ll mc){
    	if(mr[mc])return mr[mc];
    	if(n-dep*2<2){
    		return 0ll;
    	}
    	ll ret=0;
    	for(int i=1;i<=n;i++){
    		if(vis[i])continue;
    		for(int j=i+1;j<=n;j++){
    			if(vis[j])continue;
    			vis[i]=vis[j]=true;
    			ret=max(ret,gr[i][j]+dfs(dep+1,mc|(1<<i-1)|(1<<j-1)));
    			vis[i]=vis[j]=false;
    		}
    	}
    	return mr[mc]=ret;
    }
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++){
    		for(int j=i+1;j<=n;j++){
    			scanf("%lld",gr[i]+j);
    		}
    	}
    	res=dfs(0,0);
    	printf("%lld\n",res);
    }
    
    • »
      »
      »
      11 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      for(int i=1;i<=n;i++) $$$\newline$$$ for(int j=i+1;j<=n;j++)

      I am pretty sure it is $$$O(n^2 \cdot 2^n)$$$

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

        Yes yes yes it's nested in dfs but look at here:

        if(mr[mc])return mr[mc];
        

        Since the $$$O(n^2)$$$ part works only if the current status is not evaluated, and there are at most $$$2^n$$$ possible status in mr so the time complexity is $$$O(2^n)$$$.

        It's pretty fast and it only takes 13ms running.

        The submission is here

»
11 месяцев назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

Very cool tasks! Solved A — F (F is the most beautiful as for me). Thanks!

»
11 месяцев назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

What was solution for D?

»
11 месяцев назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

If you go deep into the standings you can see some curious things:

First example
Second example

What's the point of this anyway? Trying to disrupt the judge and the contest? Somehow inflate the ratings? (don't google atcoder rating inflation)

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

    kl university has mandated for students to take part in atcoder contests , so they are genuine accounts

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

      That's wild, I guess the usernames are students' internal ids? Well then, best of luck

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

        Yes , and most of them have solved same number of problems as solns would be shared by students in their class groups as soon as someone solves it

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

I get 14 penalties in D...

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

For problem G, why does the following not work? Doing a bfs from node B and checking if nodes A and C are visited or not

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

E<<<D.

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

Isn't G just checking if we can reach c from b without crossing a and similarly reach a from b without crossing c and just check if we traversed any bridge edge more than once in the whole process. I could only pass 76/93 using this..can anyone please point out the mistake.

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

What algorithm doesn't be TLE of D?

»
11 месяцев назад, # |
Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

Editorial of D: Use bitmasks DP to enumerate all possible methods

Me: SIKE I am abusing the wide variety of libraries in Python to solve this

import networkx as nx
G=nx.Graph()
edge=[]
n=int(input())
adj=[[0]*n for i in range(n)]
for i in range(n-1):
  li=[*map(int,input().split())]
  for j in range(i+1,n):
    edge.append((i,j,li[j-i-1]))
    adj[i][j]=li[j-i-1]
G.add_weighted_edges_from(edge)
a=sorted(nx.max_weight_matching(G))
ans=0
for i,j in a:
  ans+=adj[i][j]
  ans+=adj[j][i]
print(ans)
»
11 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I wish there was a way to filter out submissions based on the programming language.

Searching For
»
11 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Why does problem G need network flow? I only use Yuanfang tree to solve this problem

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

I think my E should have worked but it gave WA. Can anyone tell me where I got it wrong.

Approach
  • »
    »
    11 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    This approach is correct,you must have some mistake in implementation.

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

      I also thought the same but couldn't figure it out.

      Code
      • »
        »
        »
        »
        11 месяцев назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        This line is wrong : x += t[i] — t[i — 1] — 1;

        You need to add this difference to all previous indexes : x += (i)*(t[i] — t[i-1] -1);

        My code- Code

»
11 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Was problem E easier than D?

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

I used a shrink point to solve G, but it got WA. Can anyone explain why this is?

code here

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

Oh my god, I wasted so much time on D. I don't know why, but I even used min cost flow on that problem...

my submission

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

https://atcoder.jp/contests/abc318/submissions/45195803 What's wrong with my approach to problem E? I can't figure out. Please Help.TIA.

»
11 месяцев назад, # |
Rev. 2   Проголосовать: нравится +8 Проголосовать: не нравится

May I ask if we can solve G without network flow?

And also,can someone explain to me the meaning of "mf_graph" in the atcoder library or give me a link to let me know about it?

thanks.

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

How to solve G by tarjan? I see someone solve it by tarjan

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

For Problem D, why does the editorial (website) say that we can reduce the time complexity by breaking at the first unvisited node? I don't quite understand how that could guarantee all the possibilities are visited, I thought some transitions would be ignored this way?

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

How to do F?

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

    (Maybe different approach from editorial) Let us draw $$$N$$$ graphs of $$$y=|x-X_i|$$$. We can see that there are at most $$$O(N^2)$$$ intersections, and so the order of distance changes at most $$$O(N^2)$$$ times. The rest can be done for each possible order of distances. (Check the possible intervals between each adjacent $$$x$$$-coordinate of the intersections) Everything can then be done in $$$O(N^3\log N)$$$. There is an $$$O(N^2\log^2 N)$$$ solution improving from this, but I just don't want to explain that one.

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

      Can you please provide your submission link for the same?

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

        It's just the approach, I could not finish the code yet during contest (I went for G instead). I can write it in pseudocode if you need it.

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

          Yeah, A pseudocode would also be helpful. Thanks!

          • »
            »
            »
            »
            »
            »
            11 месяцев назад, # ^ |
            Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
            Input: X (points), L (length of robot legs)
            Output: ranges (intervals where head can exist)
            
            breakpoints = []
            for i in 0 ~ n-1
              for j in i+1 ~ n-1
                append (X[i]+X[j])/2 to breakpoints
            append -3e18 and 3e18 to breakpoints
            sort breakpoints, and remove duplicate elements
            b <- len(breakpoints)
            ranges = []
            for i in 1 ~ b-1
              x=(breakpoints[i-1]+breakpoints[i])/2
              sort X by distance from x
              range = [breakpoints[i-1]; breakpoints[i]]
              for j in 0 ~ n-1
                range = intersection(range, [X[i]-L[i]; X[i]+L[i]])
              append range to ranges
            return ranges
            

            That should do.

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

As in another solution of problem D (by evima), it has been mentioned one could easily pass all the test cases by brute force. So, how could implement it brute-force?

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

I struggled on Ex for a long time and realized that my solution is completely wrong 50min after contest XD

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

In this problem, we can use an algorithm called Round-square tree. In a round-square tree, each of the original points corresponds to a round point, and each extremely large point bi-connected subgraph corresponds to a square point.

This is editorial of G. And i want to ask what is each extremely large point bi-connected subgraph?

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

in problem G I tried to find if there is a path from A to B not going through C and from B to C not going through A anyone can provide a counter test or explain why this idea is wrong?

  • »
    »
    11 месяцев назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится
    6 6
    5 1 6
    1 2
    1 3
    2 4
    3 4
    4 5
    5 6
    

    In this graph are paths $$$1-3-4-5$$$ and $$$1-2-4-6$$$. They meet the conditions you have provided, but they are not vertex-disjoint.

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

why we can't use dijkstra in G: my submission (fails) https://atcoder.jp/contests/abc318/submissions/45201907

ll dist[i][0][0]= the distance from source to node i such that we didn't encountered B in the path and we didn't already saw c;

ll dist[i][1][0]= .... that we encountered B in the path and did not saw c

ll dist[i][1][1]= .. we encountered b and we encountered c

and I check all the neighbors of c if dist[neighbor][1][0] is <INF. why this does not work? upd: this test case: 4 3 2 1 3 2 4 1 4 3 4 does the job to prove that the solution does not work.

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

формулировки задач написаны плохо

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

I solved problem D with bitmask dp, but different from all solutions I've seen in comments. $$$dp[mask]$$$ is the best solution for that mask. Then we have that $$$dp[(1«i)|(1«j)] = d[i][j]$$$, where $$$i<j$$$. Then for every mask we iterate through all of its submasks trying to find an optimal solution. Time complexity is $$$O(3^n)$$$.

Code

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

You are right, but Genshin Impact is a new upgraded open world game adventure game independently developed by the official of MiHoYo. Mobile games originated in a world called "Tivat", where the chosen person is given the "Eye of God" to guide the power of the stars. We will play a mysterious character named "Traveler" who meets friends with different temperaments and different abilities in his free travel. We will defeat the strong enemy with them and find the separated family. In addition, we will gradually discover the truth behind the "Genshin Impact".

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

Can anyone help me with my submission on G? Link

I tried to find a shortest path from A to B, then deleted all nodes in a shortest path between them (expected B), then I found a shortest path from B to C. If it exists, the answer is Yes. Then I tried to do the same thing with tuple (C, B, A). But I received WA verdict. I have tried to generate many random tests but I can't find any wrong case. Thanks.

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

Why does the following solution not work for G? (73 AC, 20 WA)

Create a DFS tree rooted at $$$A$$$. Denote $$$lca(B,C)$$$ as $$$BC$$$.

If $$$BC = B$$$, there is a straight path $$$A\to B\to C$$$.

Otherwise, there should be a back edge from the subtree of $$$B$$$ somewhere before $$$BC$$$. Say there is a back edge from $$$V$$$ to $$$U$$$, where $$$V$$$ is in the subtree of $$$B$$$, $$$lca(U,BC) = U$$$ and $$$U\neq BC$$$. There is a path $$$A\to U\to V\to B\to BC\to C$$$.

In other cases, there is no possible path.

  • »
    »
    11 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится
    Testcase
    Graph

    Basically, you're not forced to go to strictly below B via an back edge, you can very well land above B because of the other back edges. I am pretty sure there can't be any usual dfs tree solution

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

What is the solution of E?

»
11 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

In editorial of F, how can we say it confidently ? When its elements are sorted in ascending order as S1, S2,…, S∣S∣, then for each 2≤i≤∣S∣, all x with Si−1 +1≤x≤Si satisfy the condition if and only if x=Si does.

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

Hello, can you explain why this code is not producing any output (for the 3rd problem):

#include <bits/stdc++.h>
using namespace std;
int main (){
  ios::sync_with_stdio (0);
  cin.tie (0);
  int n, d;
  long long int p;
  long long int sum = 0;
  cin >> n >> d >> p;
  vector < int >arr;
  for (int i = 0; i < n; i++)
    {
      int a;
      cin >> a;
      arr.push_back (a);
    }
  sort (arr.rbegin (), arr.rend ());
  for (int i = 0; i < n; i += d)
    {
      long long int cnt = 0;
      if ((n - i) > d-1)
	{
	  for (int j = i; j < j + d; j++)
	    {
	      cnt += arr[j];
	    }
	}
      else
	{
	  for (int j = i; j < n; j++)
	    {
	      cnt += arr[j];
	    }
	}
	if(cnt>p){
	    sum+=p;
	}
	else{
	    sum+=cnt;
	}
    }
  cout << sum << "\n";
  }
// Thank you