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

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

We will hold Denso Create Programming Contest 2024(AtCoder Beginner Contest 361).

We are looking forward to your participation!

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

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

Contest Topic Predictions for ABC:

A will be brute force.

B,C and D will be a Graph/Segment Tree/Advanced DP Problem/BS on answers/Sweepline.

E,F and G will be advanced data structures, MST, ternary search, NP Hard and 3 SAT problem.

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

Are there any Chinese?

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

I couldn't solve problem B any more! Because my maths is terrible, I couldn't imagine those cubiods' location!

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

    Disclaimer: contest is over now so we are allowed to discuss solutions.

    Define a boolean function $$$f(x_1, y_1, x_2, y_2)$$$ to be true if the ranges $$$(x1, y1)$$$ and $$$(x2, y2)$$$ intersect. (Take note of the open intervals).

    Then, the two cuboids intersect if and only if $$$f(a, d, g, j)$$$, $$$f(b, e, h, k)$$$ and $$$f(c, f, i, l)$$$ are all true.

    My (messy) solution. I find it funny how I solved the problems in the order A CDEF B.

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

Is F a known problem? I was sure I'd find code for it somewhere online but could only find a paper on it.

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

This solution for F gives WA for 2 test cases,can anyone help?

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

This was a great contest, enjoyed all problems and this is my first time solving A-F. B was a bit annoying tho.

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

This contest was easier than usual, hmmm?

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

Oh my god

There is an original problem

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

My logic for E was as follows: The optimal path will start from a leaf and end at another leaf. Let's say the two optimal leaves are a and b, and their LCA (lowest common ancestor is) c, then all the edges in the tree will be traversed twice except the ones between a and c, and b and c. Hence we want to maximise the sum of those edges.

For this I iterated over all the vertices assuming them as LCA and found out the maximum value of highest depth. See my code for more details: https://atcoder.jp/contests/abc361/submissions/55306890

But I'm getting Wrong Answer on 5 test cases. Can anyone help me find out the issue here?

Update: Found the error. I needed to use multiset instead of set

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

D cooked me ,time to focus on implementation

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

how to solve d?

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

    D is a brute force search problem. I did double-ended BFS. It is a bit overkill but I used this because I didn't want to TLE, although I've seen normal BFS work too.

    Edit: downvoters please explain?

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

      could you please explain ?? with your code ?

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

        I wrote a normal BFS solution as well. I will be using this code because it is easier to understand. However, the prerequisites are that you understand and know how to apply BFS algorithms. If not, a simple search will suffice.

        Starting with main(), we first cin>>n>>st>>te. To make our lives easier, we add ".." to the end of st and te. Now that we have initialized our start and goal states, we carry out bfs().

        Moving onto bfs(), the first line should be fairly obvious: if st==te then we clearly return 0. Otherwise, we start with some more initializing.

        unordered_map<string, int> d tracks the distance from st, i.e. d[s] is the minimal number of operations required to get from st to s. Then, we want to find d[te].

        unordered_map<string, bool> vis tracks whether we have already processed a string, i.e. if vis[s]=1, then we have already processed s, and we shall not process s again.

        queue<string> q is the standard BFS queue. Actually, all of these initializing things should make sense if you know BFS.

        The main idea of the BFS is that we start from a string u and brute force every string v that can be reached from u in 1 operation. To do this, we first add st to q, set d[st]=0 and vis[st]=1. These should be self-explanatory.

        Then, to find all strings v that can be reached from u in 1 operation, we first initialize an integer pos, which is the position of the gaps, i.e. $$$u[pos]=u[pos+1]='.'$$$. Now that we know the gaps, we brute force swapping every adjacent characters with $$$[pos, pos+1]$$$. We do this by looping from i=0 to i=u.size()-2. Note that we don't loop to i=u.size()-1, because then i+1 will be out of range of u. We need some additional if conditionals to ensure that the intervals $$$[i, i+1]$$$ and $$$[pos, pos+1]$$$ don't overlap.

        Then, to swap $$$[i, i+1]$$$ and $$$[pos, pos+1]$$$, simply taking swap(v[i], v[pos]) and swap(v[i+1], v[pos+1]) suffices. The rest are all standard BFS procedures.

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

how to do f?

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

    In C++ it is actually possible to just store every a^b with b>=3 in a set and check that stored value is not a square of some other number by finding an integer square root. Only caveat is to use binary search for finding an integer square root to avoid precision issues. Answer is int_sqrt(n) + set size.

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

Why this time abc361 have a same problem with luogu(an oj in China)?

The same problem in luogu: https://www.luogu.com.cn/problem/P9118

There is a discuss in luogu recently: https://www.luogu.com.cn/discuss/845537

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

Is F based on Mobius Function? I believe F is Inclusion-Exclusion, but could not figure out which values to include/exclude in time.

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

There's an exactly same problem from the National Olympics in Informatics (Spring Contest, 2023) in China, even the samples are same (original sample #3->sample #1, original sample #4->sample #3). Is it a concidence?

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

https://www.luogu.com.cn/problem/P9118 You know that F is an known problem,but you don't know that this problem is a pro version of F.

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

Solved ABCD,problem B is funny

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

Is there an explanation as to why G isn't commonly included in official editorials?

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

I noticed a strange behaviour in c++ today while writing code for problem D. When I use & sign before "it" in the code, the output is some gibberish like "��q{xU"

    ll n = 16;
    string s = "BBBWBWWWBBWWBW..";
    queue<pair<ll,string>>q;
    q.push({n,s});
    while(!q.empty()){
        ll sz = q.size();
        while(sz--){
            auto &it = q.front();
            q.pop();
            ll pos = it.first;
            string str = it.second;
            cout<<"str = "<<str<<endl;
        }
    } 

But when I remove the & sign, I get the expected output "BBBWBWWWBBWWBW..". Can someone explain what is this and why is this happening ?

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

    You use & when you want a reference to the value. i.e. for (auto & i : v) i++; will increase all elements in a vector, while for(auto i : v) i++; will not affect the original vector. You are getting a reference to the front of your queue, then removing the front, so you may get some garbage because you're referencing something that doesn't exist.

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

If anyone could tell me the idea for G that would be great. I tried the following:

First, we clearly just want to find all enclosed areas. Let pair<int, int> f[i] denote the coordinates of the i-th stone. Then, we connect a (bidirectional) edge from $$$u$$$ to $$$v$$$ if |f[u].first-f[v].first|<=1 and |f[u].second-f[v].second|<=1. Then, an enclosed area is analogous to a cycle in this graph. If we have a cycle $$$a_1, a_2, \dots, a_n$$$ in this graph, we can calculate the number of lattice points enclosed by the polygon formed by f[a[1]], f[a[2]], ..., f[a[n]] by using Pick's Theorem. We can calculate the area using shoelace and "reverse engineer" the number of lattice points enclosed by the polygon using Pick's Theorem. Summation of this should give us the answer.

This, however, is giving WA. If anyone could correct me, that would be greatly appreciated.

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

Many thanks to yuto1115 for sharing an amazing solution of G — Go Territory (*ˊᗜˋ*)/ᵗᑋᵃᐢᵏ ᵞᵒᵘ*

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

    I totally agree. During the contest I came up with the original idea (from another editorial) and failed to consider all cases properly. Actually, it took me nearly a dozen of submissions after the contest for all tests to be passed. I was wondering how so many people during the contest did it so fast and clean. After reading about yuto1115's approach I feel really stupid, but now I fully understand how this problem should have been solved during the contest. For sure, one of the most educational problems I've seen so far on AtCoder.

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

hey guys. how to solve F?

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

    there is said to be a brute force solution, but i cannot really understand that. my solution is to use dp and inclusion-exclusion principle. first, we can ignore 1 as it is too special. then let f[x] be the number of integars between 1 and N that can be written as pow(p, x). we can calculate it with floor(pow(n, 1/x)) - 1 (you may need to implement bisection method to avoid precision problem with these cmath functions). but there is obviously some duplicated integars calculated. for example, 2^6 is in f[6] while also in f[3] as 4^3. to avoid this, you can substract all f[x*j] from f[x] where j are integars greater than 2. the reason is simple: we calculate an integar only in f[x] where x is the greatest possible. by doing this all f[x] we calculated includes no duplicated integars. we can get the sum of all f[x] as the answer. lastly dont forget the 1 we excluded previously. my code

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

      thanks! I still don't understand why your solution works. (the inclusion-exclusion part). Can you prove that you're not overcounting (or undercounting) anything?

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

        if an integar x is going to be counted, it can be written as p^q, let assune a case where q is the greatest. in another word, if we decompose the prime factors of x, the gcd of all the index of the factors is q. now we can learn that for every integar x there exist an only q which is greatest possible. as 2^60 > 1e18, all the q of the integars we are counting is no greater than 60, so we can enumerate q from 60 to 2. for each m as a factor of q. m < q, x = p^q = (p^(q/m))^m. when we are calculating f[m], such x is also calculated in f[q], so we substract it. and m*j (j>=2) can enumerate all the integars that have a factor m and is greater than m. when m = q, in this case we will not substract f[q] from f[m] because m*j>m. therefore the f[m] remaining includes only x=p^m where m is the greatest and it will make the following recursion holds true. (please forgive my terrible wording as i am not a native english speaker)

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

        btw, a similar technique is also performed in this problem (although i think that is much harder)

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

I got 2 WA on F, i am not sure whether it is not the correct solution or it is just the precision problem.

#include<bits/stdc++.h>

long long n;
int mem[10000002];

long long qp(long long p, long long q) {
	long long r = 1, b = p;
	while (q) {
		if (q & 1) r = r * b;
		b = b * b;
		q >>= 1;
	}
	return r;
}

long long f(long long x) {
	if (x == 0) return 0;
	if (x <= 1e7) {
		if (mem[x]) return mem[x];
	}
	long long res = 0;
	for (int i = 2; i <= 61; i ++) {
		
		long long l = floor(pow((long double)x, (long double)1.0 / i) + 1e-9);
		res += l - f(l);
	}res ++;
	if (x <= 1e7) mem[x] = res;
	return res;
}

signed main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0); std::cout.tie(0);
	mem[1] = 1;
	std::cin >> n;
	std::cout << f(n);
	return 0;
}
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is there any way to know what would their CF rating be?