atcoder_official's blog

By atcoder_official, history, 9 months ago, In English

We will hold Japan Registry Services (JPRS) Programming Contest 2025#2 (AtCoder Beginner Contest 415).

We are looking forward to your participation!

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

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

glhf!

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

My first time!

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

why me fifth problem wrong 4 test bag

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

How to do C? I find it more difficult than D

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

    same here

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

    same here

    deduced the logic of D in like less than 5 minutes but was stuck on C for around 25 minutes but couldnt think of anything

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

    Do a BFS solution, starting from the mask 0. To get the next masks for each mask, iterate to find each bit that are still turned off of the mask, and turn it on. If it is a safe state to reach, and also hasn't been visited, then it can be pushed to the queue.

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

      dp is ok

      Let dp [i] represent whether the i-th drug can be safely synthesized What is the dynamic transfer equation and what do you think

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

My DP solution for problem E does not work on 4 cases. It's a modified minimum path implementation. Can someone give me a hint on those 4 cases?

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

How to solve F? Some kind of a SegTree variation?

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

    don't know if it is intended, but I did it this way. submission

    Merging nodes, with each node having prefix, suffix and mid of the highest frequency letter and the letter

  • »
    »
    9 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +6 Vote: I do not like it

    Use a segment tree (with each node representing one substring) to collect the following information

    1. the length of that substring
    2. the longest prefix with the same character as the first one in that substring
    3. the longest suffix with the same character as the last one in that substring
    4. the function value in that substring (i.e. longest substring in that substring with same letter)
    5. what is the first letter
    6. what is the last letter

    it's kind of like CSES 1190 and CSES 3226 combined, but with strings instead of integer additions.

    submission to F: here

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

    I solve it: Code:

     #include <bits/stdc++.h>
              using namespace std;
              struct Node 
    		  {
                  char l_char, r_char;
                  int l_len, r_len;
                  int max_len;
                  int len;
                  Node() = default;
                  explicit Node(char c) 
    			  {
                      l_char = r_char = c;
                      l_len = r_len = 1;
                      max_len = 1;
                      len = 1;
                  }
              };
              Node merge(const Node& left, const Node& right) 
    		  {
                  Node res;
                  res.len = left.len + right.len;
                  res.l_char = left.l_char;
                  res.r_char = right.r_char;
                  // left consecutive
                  res.l_len = left.l_len;
                  if (left.l_len == left.len && left.r_char == right.l_char) 
    			  {
                      res.l_len += right.l_len;
                  }
                  // right consecutive
                  res.r_len = right.r_len;
                  if (right.r_len == right.len && left.r_char == right.l_char) 
    			  {
                      res.r_len += left.r_len;
                  }
                  res.max_len = max(left.max_len, right.max_len);
                  if (left.r_char == right.l_char) {
                      res.max_len = max(res.max_len, left.r_len + right.l_len);
                  }
                  return res;
              }
              void build(vector<Node>& tree, int idx, int l, int r, const string& s) 
    		  {
              	
                  if (l == r)
    			   {
                      tree[idx] = Node(s[l]);
                      return;
                  }
                  int mid = (l + r) / 2;
                  int left_child = 2*idx+1;
                  int right_child = 2*idx+2;
                  build(tree, left_child, l, mid, s);
                  build(tree, right_child, mid+1, r, s);
                  tree[idx] = merge(tree[left_child], tree[right_child]);
              }
              void update(vector<Node>& tree, int idx, int l, int r, int pos, char c) 
    		  {
                  if (l == r) 
    			  {
                      tree[idx] = Node(c);
                      return;
                  }
                  int mid = (l + r) / 2;
                  int left_child = 2*idx+1;
                  int right_child = 2*idx+2;
                  if (pos <= mid) 
    			  {
                      update(tree, left_child, l, mid, pos, c);
                  } 
    			  else 
    			  {
                      update(tree, right_child, mid+1, r, pos, c);
                  }
                  tree[idx] = merge(tree[left_child], tree[right_child]);
              }
              Node query(vector<Node>& tree, int idx, int l, int r, int ql, int qr) 
    		  {
                  if (ql <= l && r <= qr) 
    			  {
                      return tree[idx];
                  }
                  int mid = (l + r) / 2;
                  int left_child = 2*idx+1;
                  int right_child = 2*idx+2;
                  if (qr <= mid) 
    			  {
                      return query(tree, left_child, l, mid, ql, qr);
                  } 
    			  else if (ql > mid) 
    			  {
                      return query(tree, right_child, mid+1, r, ql, qr);
                  } 
    			  else 
    			  {
                      Node left_node = query(tree, left_child, l, mid, ql, mid);
                      Node right_node = query(tree, right_child, mid+1, r, mid+1, qr);
                      return merge(left_node, right_node);
                  }
              }
              int main() {
                  ios::sync_with_stdio(false);
                  cin.tie(0);
                  int n, q;
                  cin >> n >> q;
                  string s;
                  cin >> s;
                  vector<Node> tree(4 * n);
                  build(tree, 0, 0, n-1, s);
                  while (q--) 
    			  {
                      int type;
                      cin >> type;
                      if (type == 1)
    				   {
                          int i;
                          char c;
                          cin >> i >> c;
                          i--;
                          update(tree, 0, 0, n-1, i, c);
                      } 
    				  else 
    				  {
                          int l, r;
                          cin >> l >> r;
                          l--; r--;
                          Node res = query(tree, 0, 0, n-1, l, r);
                          cout << res.max_len << '\n';
                      }
                  }
                  return 0;
              }
    

    just to bulid a tree and do something

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

    I did something using a lazy segtree representing an array where a[i] is the streak of consecutive same characters ending at index I, and you just query the max element with the range for the answer.

»
9 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Did anyone else get AC*39 WA*1 in problem G?

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

    I did the following: Use dp to calculate the optimal solution for N<=1000. I guessed you could get to <=1000 with just 1 index. Try all M possible indices and pick the best. But WA in 1 case.

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

    I have 38 ACs and 2 WAs

    I sorted the exchange methods by $$$\frac{A}{B}$$$ from small to big, and then use each method in order, and use one as much as possible (until it can't be used) and then move on. I don't know why WA in 2 cases

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

      try this: 13 2 13 3 8 2 I thought exactly the same as you. But greedy didn't seem to work.

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

    Same as me, I tried to find the cycle and were very pleased when 39/40 passed and it is still grey, and the last case just turn yellow. Kill me !

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

    Yes, N <= 1000 -> N <= 100000 with observation that we have <= 300 useful pairs and it passed

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

    Can anybody prove that it is optimal to keep using one operation when $$$n$$$ is large enough, say, 100000?

    Rather mysterious.

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

    I think when you violently DP, you should sort the items by the value of the $$$a_i$$$ from largest to smallest to ensure that the order in which you choose items is optimal.

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

I write a (max, +) matrix pow in G and don't find $$$V^3\log{n}$$$ has already exceed $$$10^9$$$.

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

F solution code looks unnecessarily complicated. Here's mine. Also, I get that ABCs are meant to be standard but this F was just bad cuz it's very standard + you could use integers and nothing would change.

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

where to get editorial for these contests?

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

How to do D?I tried three ways to sort the array,but none of them is right.

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

https://atcoder.jp/contests/abc415/submissions/67748782

why i got 44*AC 2*WA on problem E?

and i dont think there's something wrong

»
9 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

I solved G in last 6 minutes and I reached 1 Dan!!! E and G are interesting.

»
9 months ago, hide # |
Rev. 3  
Vote: I like it +3 Vote: I do not like it

In problem G, I try to find the minimum "cycle", which means dp[i] = dp[i-cycle] + constant hold for every i when i is large. However, I got 39 AC and 1 WA on the last test case. How large cycle can be given the problem constraint ?

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

For Question D Any idea why this logic fails ?

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

    your code fails this following test case:

    23 6
    9 7
    1 1
    5 3
    16 4
    21 7
    12 5
    

    Correct output: 11, your code's output (incorrect): 0

    I think the reason why it fails is due to the incorrect calculation of the number of times the operation will be applied and the value of variable ct after applying a number of operations.

    Here is my in-contest submission: https://atcoder.jp/contests/abc415/submissions/67755510

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

      a=b is not allowed in test cases , but your second input has 1 1 , no of stickers will be infinite in this case

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

Did anyone know what test case "04_handmade_04.txt" in problem G is ? Very curious.

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

In F , can't we simply make segtree with hash of 26 letters?

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

Can someone help me understand the solution to D?

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

https://atcoder.jp/contests/abc415/submissions/me can anyone tell the error in this

»
9 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

I think today's ABC is really good for education. From problem C to F, the topics are [bitmask+bfs], [greedy+math], [binary search+dp] and [data structure(segment tree)].

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

    Can you explain D?

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

      Yes, of course. It is my pleasure if I could help little.

      Here are some important observations for solving this problem.

      1. Suppose that there are two strategies to reach the following two states. State1, we have already got y stickers and currently have n-x1 empty bottles left. State2, we have already got y stickers and currently have n-x2 empty bottles left. if n — x1 <= n — x2, it is always better to choose the second strategy, otherwise we choose the first one. In a word, if we could get y stickers, it is better to lose as few empty bottles as possible. This has already inspired us that greedy algorithm might work, so we are going to have a try.

      2. For some pair (a,b), it in fact implies that we would lose a-b empty bottles in order to get one sticker (as long as we have at least a empty bottles now). So, according to observation 1, we should choose the pair (a,b) which has the minimal value of a-b. If there are two pairs (a1,b1) and (a2,b2) which satisfy a1-b1=a2-b2, we should choose the one with smaller a1. For instance, assume that we have 6 empty bottles now, and there are (a=7, b=6) and (a=3,b=2). Of course we should choose (a=3,b=2).

      3. Now the solution is somehow straightforward. We sort all the pairs (a,b), first by a-b in an increasing order, and if there are multiple pairs which have the same value of a-b, we should then sort them by the vaule of a in an increasing order (we could also delete those which have larger value of a). Finally, we start from the first pair until the last one, and try to get as many stickers as possible for the current pair.

      4. Given pair (a,b) and n empty bottles, how to compute the most number of stickers that we could get by using only this pair? My method is to first find the largest q such that n-q*(a-b)>=a holds, which is, q<=(n-a)/(a-b), and q+1 is the answer. The idea is that, after q times, we still have the last chance to get one more sticker, and thus the answer is q+1.
»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem E,

Start with 0 coins, initially and perform the operations in the dp using bfs like algo. and store the max parent from which the dp is getting updated, traversing back the path from (h - 1, w - 1) should give us the coins required at the start.

Here is my submission: https://atcoder.jp/contests/abc415/submissions/67867006

why my logic is wrong, can anyone please help :)

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

Can someone help please, not sure why this code is TLE https://atcoder.jp/contests/abc415/submissions/68073531

I used binary search and BFS on grid.