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

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

We will hold KAJIMA CORPORATION CONTEST 2024(AtCoder Beginner Contest 340).

We are looking forward to your participation!

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

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

Hopefully I will bring my A game today and become cyan

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

Hope to place in Top 500

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

Hopefully that I can solve all the problems like last time:)

ps:last time I participate in ABC I become 1600+ which is 2 Kyu:)

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

Participated in ABC for the first time!

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

GOOD LUCK!!!

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

Want to solve for F!!!

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

F is way too easy for 525 points.

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

What is the C problem based on? How to solve it? Does it involve some observation? Can't use DP because of the constraint on n but I couldn't solve it at all throughout the contest. :/

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

How to solve F?

I know that the third point of the triangle should be on a line parallel with (0, 0), (X, Y) line. and we can find the line format(ax+b) but I don't know how to find an integer point on this line.

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

Are centroid solutions passing in problem G?

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

My thought process for E: Mancala 2.

Usually in these type of problems, people struggle with off-by-one errors. A clever way to avoid these bugs is to rely on Euclid's Divison Lemma. It says that ANY number can be written as :

$$$ num = div *q + rem $$$

where $$$div$$$ is read as Divisor and $$$0 \leq rem \lt div$$$. But that's not all, you can quickly find out $$$q$$$ and $$$rem$$$ via these equations.

$$$ \begin{align} q &= num / div \\ rem &= num \% div \end{align} $$$

Suppose we are performing the operations for the the box with $$$num$$$ balls. Then,

$$$ \begin{align} num &= n*q + rem \\ q &= num / n \\ rem &= num \% n \end{align} $$$

Now, it's easy to see that EVERY box will receive $$$q$$$ balls in Phase 1. And in phase 2, a total of $$$rem$$$ boxes would receive one ball each.

Code

Submission

Now, how do we optimize this. Notice that Phase 1 is simply adding an increment $$$q$$$ to all elements of a subarray. While phase 2 is adding $$$1$$$ to possibly 2 subarrays (a prefix and a suffix). Hence, we need a data structure that can support range increment and point query.

Atcoder's library provides a data structure that can support range sum and point update queries. Now, how do we use it for this scenario? We can do so by simulating difference array. Some people like to maintain the difference array in the segment tree on the fly, however, I personally write a wrapper around it to make the code more readable. A sample implementation can look like.

Code

Finally, we can use our custom data structure to perform range updates. The only challenge is to handle the updates via $$$rem$$$. But notice that it will always be a suffix and prefix update. Hence, you can first update the suffix, and if there are still some balls remaining, you can do a prefix update.

Code

Submission

I am not sure if segment tree was an overkill for this problem. If it was, I'd love to know your alternate solutions.

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

Two minutes more please :'(

Screen-Shot-2024-02-10-at-17-43-18

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

Any Hint for $$$F$$$?

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

Any ideas about D? I solved it using dfs but get TLE :(

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

Anyone tried to solve F as a computational geometry problem?

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

How to do B? I did it for half an hour but I can't solve it.

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

For D: Super Takahashi Bros, if you were not able to intuitively figure out why Dijkstra would work for the problem, I've written a tutorial on how to think of Dijkstra problems via BFS (which is usually easier to reason about).

https://cfstep.com/training/tutorials/graphs/dijkstra-is-bfs-in-disguise/

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

Can someone please help me figure out why my $$$O(n \log^2 n)$$$ small-to-large merging TLEs only on star graphs?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
  • First & Second -> Cake walk
  • Third -> DP.
  • Fourth -> Dijkstra’s (I wasn't able to figure out during the contest)
»
3 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

I think intended solution of $$$F$$$ mayn't be linear diophantine otherwise why would they say that the area has to be 1 not any other integer

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

Can anyone tell me how can I see the test cases of some problem at atcoder?

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

Can someone please help me understand why my code is giving RE for just 1 test case of Problem D. All other test cases are AC.

#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	vector<vector<pair<int, int>>> v(n);

	for (int i = 0; i < n; i++)
	{
		int a, b, x;
		cin >> a >> b >> x;
		x--;
		v[i].push_back({a, i + 1});
		v[i].push_back({b, x});
	}

	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	vector<int> dist(n, LONG_MAX);
	vector<bool> visited(n, false);

	pq.push({0, 0});
	dist[0] = 0;
	while (!pq.empty())
	{
		pair<int, int> p = pq.top();
		pq.pop();

		int x = p.second;

		if (visited[x])
		{
			continue;
		}
		// cout << "reached\n";
		visited[x] = true;

		// for (auto r : v[x])
		// {
		// 	cout << r.first << " " << r.second << '\n';
		// }

		for (int i = 0; i < v[x].size(); i++)
		{
			int to = v[x][i].second;
			int weight = v[x][i].first;
			if (dist[x] + weight < dist[to])
			{
				dist[to] = dist[x] + weight;
				pq.push({dist[to], to});
			}
		}
	}

	cout << dist[n - 1];
}

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

Problem G can be solved using small to large merging. My submission

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

Deleted

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

Why my code for E giving TLE??

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

Yay, I first time solved problem G by myself without using hints (after contest though). This time it is quite simple. Usually it requires some strange not widely known theorems, but this one didn't required anything except dfs and simple combinatorics.

My solution.

Solve for each color independently. Solve first this simple task: there are vertices of only one color. We need to calculate number of subgraphs-trees (How to call subgraph, which is a tree, actually?). Let $$$dp[v]$$$ is the number of subgraph-trees, which are in subtree of $$$v$$$ and have $$$v$$$ in them. Then $$$dp[v] = (dp[c_1] + 1) \cdot (dp[c_2] + 1) \cdot \dots $$$, where $$$c_i$$$ are children of $$$v$$$. And the answer is $$$res = dp[1] + dp[2] + \dots$$$.

Now back to full problem. Can we for every color just create a graph with edges $$$u-v$$$ if $$$u$$$ is lowest ansestor of $$$v$$$ with the same color and then run the same algorithm? Well, not really. There can be a situation, when two vertices of some tree have $$$lca$$$ of some othere color. Then path between them will not be calculated. How to fix it? Let's just add all those $$$lca$$$ to the tree and do the same. There are not many $$$lca$$$ and to get them all, we can build an euler tour on vertices of this color and add $$$lca$$$ for every two adjacent vertices.

How the $$$dp$$$ changes? Now we have some additional fictitious vertices $$$v$$$, which have other color. For them we simply do two things. First, $$$dp[v] -= 1$$$, because there is no subgraph-tree with only this vertice. There are also no subgraph-trees, for which $$$v$$$ is the root, but we can use them in upper subtrees, so we need to pass them up. So, second, for such $$$v$$$ do $$$res -= dp[c_1] + dp[c_2] + \dots$$$, where $$$c_i$$$ are children of $$$v$$$.

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

For G we don't need stack to find the parents, if we sort the array of vertices again based on pre-dfs order (after adding LCAs) then for each $$$0 \lt i$$$ we have $$$LCA(x_{i-1}, x_i) = p[x_i]$$$ where $$$p[x]$$$ is parent of vertex $$$x$$$.

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

I can't find the testcases for ABC340 on dropbox, there's only upto ABC335. Do anyone know how to find?

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

Can you tell me why I am getting WA in this E solution? https://atcoder.jp/contests/abc340/submissions/50242534

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

For G: Leaf Color: I created a practice contest and blog discussing the $$$O(n)$$$ Tree DP idea for a fixed color. The editorial mentions that this is a good exercise for blue coders, so I encourage you to submit to the practice contest.