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

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

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

We are looking forward to your participation!

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

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

glhf!

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

My first time!

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

why me fifth problem wrong 4 test bag

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

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

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

    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 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +6 Проголосовать: не нравится

    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 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

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

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

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

where to get editorial for these contests?

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

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

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

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

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For Question D Any idea why this logic fails ?

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

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

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

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

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

Can someone help me understand the solution to D?

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

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

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

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 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Can you explain D?

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

      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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
9 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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.