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

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

Hello, Codeforces!

We would like to invite you to participate in the live online mirror contest of The 2026 ICPC Asia Pacific Championship next weekend. ICPC Asia Pacific Championship is the contest for top non-winning teams from all regional contests in the region to qualify to the World Finals. See the region rules and competition page for more details.

The official contest is scheduled to start at Sunday, 8 March 2026, 09:30 AM (UTC+8). The live online mirror contest is scheduled to start only 15 minutes later, to keep both contests run almost in sync. The contest is 5 hours long and consists of several problems.

Please note that we might have to postpone the live online mirror contest in case the official contest is delayed. This is to ensure that the tasks are not available to the public until the official contest starts.

The contest will use ICPC-style scoring (same as the official contest) and will be unrated. You can participate as an individual or as a team, although as a team of three members is preferred.

See you on the top of the leaderboard!

The 2026 ICPC Asia Pacific Championship Judges

[UPD]: Task analysis

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

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

rp++ rk--

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

Is the online mirror's scoreboard synced with the actual contest scoreboard?

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

There is a solution for E in $$$O((n + q)\log n)$$$, using m stacks.

https://codeforces.me/contest/2206/submission/365799729

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

    Could you explain how it works? I can't understand that.

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

      I will use 0-based indexing for convenience with mods.

      Note that $$$s_{i+1} - s_i = (a_{i+1} + \ldots + a_{i+m}) - (a_i + \ldots + a_{i+m-1}) = a_{i+m} - a_i$$$, so for all $$$i$$$, the value of $$$a_i$$$ is determined by $$$a_{i \bmod m}$$$ and the input array. More formally, $$$a_i = a_{i\bmod m} + c_i$$$ for some constant $$$c_i$$$, and we can pick $$$a_0 \sim a_{m-1}$$$ freely as long as $$$a_0 + a_1 + \ldots + a_{m-1} = s_0$$$.

      If $$$r - l + 1 \lt m$$$, then the answer is unbounded. Otherwise, we know that each query is asking for the smallest possible value of $$$\max(a_0 + x_0, a_1 + x_1, \ldots, a_{m-1} + x_{m-1})$$$ where $$$x_i = \underset{l\leq j\leq r \wedge j \equiv i\bmod m}{\max} c_j$$$.

      To get the minimum value of the above expression, consider when we can make it $$$\leq t$$$ (think binary searching on answer). We get $$$a_i + x_i \leq t$$$ for $$$0 \leq i \lt m$$$, and summing up all the equations, $$$s_0 + \sum {x_i} \leq mt$$$. Rearranging gives $$$t \geq \left\lceil \frac{s_0 + \sum {x_i}}{m} \right\rceil$$$ which is the answer.

      Now, finally, stuff that isn't in the official editorial: we process the queries in order of increasing $$$r$$$. This is nice because if we are currently answering queries with $$$r = j$$$ when $$$c_0$$$ to $$$c_j$$$ have been processed, and we see that $$$c_i \leq c_j$$$ where $$$i \lt j$$$ and $$$i \equiv j \pmod m$$$, then $$$c_i$$$'s contribution to $$$x_{j \bmod m}$$$ will be overshadowed by $$$c_j$$$.

      Therefore, we can maintain a monotonic stack for each set of indices that give the same value $$$\bmod m$$$, where the topmost elements have larger index and smaller values. If $$$c_i$$$ and $$$c_j$$$ $$$(i \lt j)$$$ are next to each other in our monotonic stack, then that means if the query left bound $$$l \leq i$$$, it will contribute $$$c_i - c_j$$$ to our answer.

      We can use a point-update, range-sum segment tree to maintain this difference array on our monotonic stack. To get $$$\sum {x_i}$$$, we just query the range sum from $$$l$$$ to $$$r$$$ at the moment we have processed $$$c_0$$$ to $$$c_r$$$. It runs in $$$O((n + q) \log n)$$$.

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

problem — K

consider this testcase

if you got WA in TC-22

1
53
00000000001111111133344555555666666666788889999999999
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится -20 Проголосовать: не нравится

I hope everyone can pass smoothly, good luck.

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

Was sqrt decomposition unintended for D? I had to use some stupid tricks to make it fit within the TL

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

someone explain solution of problem K...

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

For Problem K:

I think you can avoid binary search entirely and get an O(N) solution.

I solved it by greedily trying to generate valid solutions and just counting how many there were, breaking when no more solutions can be found. It takes O(1) to generate the next solution, and there's a maximum of N/4 solutions.

Is this a faster/simpler way of solving K, or is there a benefit of using binary search like the intended method?

373286371 2206K - Time Display Stickers

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

A greedy solution to the last question (K. Time Display Stickers) without binary search

#include <iostream>
#include <unordered_map>
using namespace std;

void solve(){
    int n;
    cin >> n;

    string seq;
    cin >> seq;

    unordered_map<int, int> freq;
    int non_zero = 0;
    int og_non_zero = non_zero;


    for (int i = 0; i < n; i++){
        freq[seq[i] - '0']++;
    }

    for (auto pr: freq){
        if (pr.second > 0){
            non_zero++;
        }
    }

    long long combinations = 0;

    while (true){
        bool d1_found = false;
        int d1;
        for (int i = 0; i < 2; i++){
            if (freq[i] == 0){
                continue;
            } else {
                freq[i]--;
                d1_found = true;
                d1 = i;
                break;
            }
        }

        if (d1_found == false){
            cout << combinations << "\n";
            return;
        }

        bool d2_found = false;
        int d2;
        int limit;
        if (d1 == 0){
            limit = 9;
        } else {
            limit = 1;
        }
        for (int i = limit; i >= 0; i--){
            if (freq[i] == 0){
                continue;
            } else {
                freq[i]--;
                d2_found = true;
                d2 = i;
                break;
            }
        }

        if (d2_found == false){
            cout << combinations << "\n";
            return;
        }

        bool d3_found = false;
        int d3;
        for (int i = 5; i >= 0; i--){
            if (freq[i] == 0){
                continue;
            } else {
                freq[i]--;
                d3_found = true;
                d3 = i;
                break;
            }
        }

        if (d3_found == false){
            cout << combinations << "\n";
            return;
        }

        bool d4_found = false;
        int d4;
        for (int i = 9; i >= 0; i--){
            if (freq[i] == 0){
                continue;
            } else {
                freq[i]--;
                d4_found = true;
                d4 = i;
                break;
            }
        }

        if (d4_found == false){
            cout << combinations << "\n";
            return;
        }

        //cout << d1 << d2 << ":" << d3 << d4 << "\n";
        combinations++;
    }
}

int main(){
    int testcases;
    cin >> testcases;

    for (int i = 0; i < testcases; i++){
        solve();
    }
}
»
4 недели назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

2206-K Time Display Stickers

My Approach:

First, I create an array of size 10 to store the frequency of each digit. I convert each character into an integer and use it as an index to count the available digits.

Then, I create four integers: st, lt, mid and ans.

After that, I start a while loop and check the condition arr[st] != 0 && st < 2.

For the hour, I select the required digits while updating their frequencies. Then, I calculate the minutes. The first digit of the minutes must be between 0 and 5.

Whenever a complete valid time can be formed, I increment ans.

The process continues until no more valid times can be constructed.

Code:

import java.util.Scanner;

public class Sol {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {
            int n = sc.nextInt();
            String str = sc.next();

            int[] arr = new int[10];

            for (int i = 0; i < n; i++) {
                char ch = str.charAt(i);
                int num = ch - '0';
                arr[num]++;
            }

            int st = 0;
            int lt = 9;
            int mid = 5;
            int ans = 0;

            while (st <= lt) {

                if (arr[st] != 0 && st < 2) {
                    arr[st]--;

                    if (st == 0) {
                        boolean hour = false;

                        for (int j = lt; j >= 0; j--) {
                            if (arr[j] != 0) {
                                arr[j]--;
                                lt = j;
                                hour = true;
                                break;
                            }
                        }

                        if (!hour) {
                            break;
                        }
                    } else {
                        if (arr[st] != 0) {
                            arr[st]--;
                        } else {
                            break;
                        }
                    }

                    boolean minuteFirstDigit = false;

                    for (int i = mid; i >= 0; i--) {
                        if (arr[i] != 0) {
                            arr[i]--;
                            mid = i;
                            minuteFirstDigit = true;
                            break;
                        }
                    }

                    if (!minuteFirstDigit) {
                        break;
                    }

                    boolean minuteSecondDigit = false;

                    for (int i = lt; i >= 0; i--) {
                        if (arr[i] != 0) {
                            arr[i]--;
                            lt = i;
                            minuteSecondDigit = true;
                            break;
                        }
                    }

                    if (!minuteSecondDigit) {
                        break;
                    } else {
                        ans++;
                    }

                } else {
                    st++;
                }
            }

            System.out.println(ans);
        }
    }
}