atcoder_official's blog

By atcoder_official, history, 10 months ago, In English

We will hold Denso Create Programming Contest 2025(AtCoder Beginner Contest 413).

We are looking forward to your participation!

  • Vote: I like it
  • +25
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it -81 Vote: I do not like it

first?

»
10 months ago, hide # |
 
Vote: I like it -77 Vote: I do not like it

qp

»
10 months ago, hide # |
 
Vote: I like it -79 Vote: I do not like it

qp

»
10 months ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

When we are trying to submit a solution, there is no way to submit. Why?? And why the task is not readable? when we click in any problem, no descriptions is opened? Is it a bug or it could be a problem in my system?

»
10 months ago, hide # |
 
Vote: I like it -30 Vote: I do not like it

hp

»
10 months ago, hide # |
 
Vote: I like it -27 Vote: I do not like it

6

»
10 months ago, hide # |
Rev. 2  
Vote: I like it -26 Vote: I do not like it

emm

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The Problem G is exactly the same as the problem CodeChef Starters 121 / CHEFESCAPE. I used a silly BFS search when I solved it nearly 1.5 year ago, and this time I use a better and easier DSU to implement it.

Solution 1.5 year ago: here

Solution today: here

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem $$$D$$$ is so annoying to implement.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For D, I tried to first separate the sequence into negative and positive part, then sort positives normally and sort negatives in reverse, then intersect them to restore the geometric sequence.

what could be the issue in the logic?

can't I just avoid floating point precision lost using big decimal?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I sorted the sequence got the cr then compared it with the next one in sequence but I think the float point error was not accounted for correctly

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    For sequences like $$$[1,1,1,-1,-1,-1]$$$ this doesn't work since the order can be random, and could lead to $$$2$$$ different value of $$$r$$$.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      True, but I did handle this edge case, whenever the number of positive and negative equal, I do two passes and check for both of them. i.e. [1, -1, 1, -1, 1, -1] and [-1, 1, -1, 1, -1, 1]

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        what about $$$[1,1,1,-1,-1]$$$ ?

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          then the count of positive and negative are not equal, I will consider the only possibility which is [1, -1, 1, -1, 1].

          or if the input is [-1, -1, -1, 1, 1], then I only consider this [-1, 1, -1, 1, -1]

          anyway, now I see what is the intended solution with GP property

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +2 Vote: I do not like it

    just sort the elements based on their absolute values and check for GP properties. Also, don't use float or double division, use long and check b^2 = a*c property of GP

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I tried that, it didn't work. Submission

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        You missed the edge cases like [2,-2,2,-2] etc. before sorting just check for this condition — absolute values of all the elements are same and difference between positive and negative elements is <=1

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
           
          Vote: I like it +1 Vote: I do not like it

          Yeah, that's so annoying

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it 0 Vote: I do not like it

          Can anyone explain me in D, why abs(neg-pos)<=1 condition is there? [2,2,2,2,2]is also a gp right? here abs(pos-neg)>1

          • »
            »
            »
            »
            »
            »
            10 months ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            see for the cases abs(neg-pos) > 1 we must check the property a[i]*a[i] == a[i-1]*a[i+1]. (array is sorted based on absolute values)

            For the cases like [-2,-2,2,2] , [2,-2,-2,2,-2] , [2,-2,-2,-2] sorting based on absolute won't work but there are possible rearrangements.

            [2,-2,2-2] and [-2,2,-2,2,-2] are possible. No possible rearrangement for third case as abs(neg-pos)>1.

            • »
              »
              »
              »
              »
              »
              »
              10 months ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              what i am asking is [2,2,2,2] is a gp but abs(pos-neg)=4>1 so according to your logic the answer should be no but it is a gp

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Thanks for your amazing F, I really enjoy it

»
10 months ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

G too easy than other rounds' G. D too rubbish than other rounds' D.

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Trash C.

F**KING AtCoder put a problem with ORIGIN IN PREVIOUS ABCs

Today's C

The origin

The exactly same code(modification is because of the different input format) can pass both problems.

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Thank you for problems D and E, I submitted G, 3 mins late.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

G is too easy for an ABC's G.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I took so long on D to find out that I forgot to check for r = +-1. Lost 20 mins to that and thus didn't have enough time to give to F. Oh well.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem G is basically a simple version of LC 3235.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

noo i miss it

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My stupid solution to problem F.

Main fact. Choose a cell. Look at answers for neighbouring cells. The first player will block the minimum one, so the second player will choose the second minimum one.

But we can't do it with a usual bfs, as the dependency is cyclic.

Idea 1. Process cells in increasing order of answer (like in Dijkstra). When the cell has at least two calculated neighbours, set the answer for it and insert it into set. This is fast and wrong, since we can miss the neighbour with less answer, which will be calculated later.

Idea 2. Do "for for" and calculate the answer for all cells as in idea 1. Do it again and again, until it stops change. This is correct and slow.

Idea 3. Do "Idea 1" ++ "Idea 2". This is AC.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone explain me in D, why abs(neg-pos)<=1 condition is there?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem D- Can anyone explain where my solution is wrong?

My Solution

I am sorting by absolute values and checking if $$$a_1, a_2, a_3$$$ be our sequence $$$a_2 \times a_2 = a_1 \times a_3$$$

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int gcd(int a, int b){
  if(abs(a)== 0){
    return abs(b);
  }
  return gcd(abs(b) % abs(a), abs(a));
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  freopen("input.txt", "r", stdin);
  int t; cin >> t;
  while(t--) {
    int n; cin >> n;
    vector <int> a(n);
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    sort(a.begin(), a.end(), [](int a, int b){
      if(abs(a) < abs(b)){
	return true;
      }
      return false;
    });
    if(n <= 2){
      cout << "Yes\n";
      continue;
    }
    int flag = 0;
    pair <int, int> r = {a[0]/gcd(a[0], a[1]), a[1]/gcd(a[0], a[1])};
    for(int i=1; i<n-1; i++){
      int fac = gcd(a[i], a[i+1]);
      if(((long long) r.second * (a[i]/fac) != (long long)r.first * (a[i+1]/ fac))){
	flag = 1;
	break;
      }
    }
    if(flag==0){
      cout << "Yes\n";
    }
    else {
      cout << "No\n";
    }
  }
}
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone help me with what's wrong with this submission for problem : D submission Logic : 1) If the array contains only positive or only negative elements then just sort the array and check for GP. 2) If there are both positive and negative elements then again sort it , but this time look where to start the GP , for example consider the first positive element and first negative element , and u can decide based off whose magnitude is greater , then alternatively we can check for if its a GP as have done in the code.

Surprisingly , I got 29 WAs , wasnt expecting the logic to be soo wrong ...

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone please help me in debugging my solution for problem D.

1)I sorted the array based on abs(value).

2)After that a general G.P check

3)And then if there is a mix of negative and positive elements then I tried checking if all the three elements are either +,-,+ or -,+,- .

Still I am getting only 3AC

https://atcoder.jp/contests/abc413/submissions/67371107

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

https://atcoder.jp/contests/abc413/submissions/67365983 why am i getting wrong ans can someone debug it

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone help me the with the approach of C?