Koo_Pung-Kei's blog

By Koo_Pung-Kei, 15 hours ago, In English

(Read before: I seldom succeed in killing the third problem before the finishing bell rings during any contests, and this time is no exception. The blog is just for inspiration and the codes given may not necessarily be the best one. Better thoughts are welcomed in the comment area from readers.)

Hello, Codeforces!

This round was a mathematical and Arcaea-ful one for me as (at least said by my rating) a newbie. The blog is to give thoughts (rather than giving the whole code block straightly) on the first 3 problems in the round, and I do hope this may inspire you as readers.

2078A - Final Verdict

Testify — void (Mournfinale) feat. 星熊南巫 marks a climax in the plotline of Arcaea. The song was released in Final Verdict, a 2022 DLC for the 2017 rhythm game.

We can easily find out that the overall average of the array will not change throughout the whole operation phase. This means only when the average of the given array equals to $$$x$$$ will the array meet the demands.

public static void solve() throws Exception {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int x = scanner.nextInt();
    int[] a = new int[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        a[i] = scanner.nextInt();
        sum += a[i];
    }
    if (sum == n * x) {
        System.out.println("YES");
        return;
    }
    else
        System.out.println("NO");
    return;
}

2078B - Vicious Labyrinth

Axium Crisis — ak+q was released in Vicious Labyrinth, a Main Story song pack released in version 1.5.0 of Arcaea.

The teleporters should make as many labyrinth residents travel to the exit as they can. So:

  • When $$$k$$$ is odd, just equip all cells other than the exit cell itself with teleporters that fly the cell occupier to the exit, and equip the exit cell with a teleporter to its nearest cell. This will make all people other than the exit occupier able to exit, and the initial owner of the exit will be only one cell away from the exit, achieving the minimum total distance.

  • When $$$k$$$ is even, equip all cells other than cell $$$n-1$$$ with teleporters to the excluded cell, and the $$$n-1$$$-th cell flies people to the exit as the interchange. The configuration can make all people other than the interchange's initial owner to the exit, minimizing the total distance.

public static void solve() throws Exception {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int k = scanner.nextInt();
    if (k % 2 != 0) {
        for (int i = 1; i < n; i++) {
            System.out.print(n + " ");
        }
        System.out.println(n - 1);
    }
    else {
        for (int i = 1; i < n - 1; i++) {
            System.out.print(n - 1 + " ");
        }
        System.out.print(n + " ");
        System.out.println(n - 1);
    }
}

2078C - Breach of Faith

Breach of Faith — Supire feat.eili's name got straightly highlighted from the problem's title. The song is from Lucent Historia, another Main Story pack of Arcaea which just got released in November 2024.

We know that $$$a_1=a_2-a_3+a_4-a_5+\cdots +a_{2n}-a_{2n+1}.$$$ The equation can be transformed to $$$a_1+a_3+\cdots +a_{2n+1}=a_2+a_4+\cdots +a_{2n},$$$ meaning that the sum of all odd-indexed elements in the array $$$a$$$ equals to that of all even-indexed ones.

There are $$$n+1$$$ elements in the left formula and $$$n$$$ in the right of the equation above. Therefore, if we choose the largest $$$n+1$$$ elements of the given array $$$b$$$ as all the odd-indexed elements and the rest for the even-indexed, indicating the lost element is with an even index in $$$a$$$, the sum of odd-indexed elements is, beyond no doubt, larger than the sum of the even-indexed ones (the lost element excluded of course), ensuring that the lost element is positive.

Suppose the element lost is $$$a_2,$$$ and think about whether $$$a_2$$$ is bound to be larger than the largest element of $$$b$$$ (let's make $$$a_1>a_3>\cdots > a_{2n+1}$$$). The given equation can be transformed to be $$$a_2=a_1+(a_3-a_4)+(a_5-a_6)+\cdots +(a_{2n-1}-a_{2n})+a_{2n+1},$$$ thus it can be reached that $$$a_2>a_1$$$ because of $$$a_{2i-1}-a_{2i}>0$$$ mentioned in our considerations in the paragraph above, which means the lost element IS the largest element of $$$a$$$, securing the pairwise distinct highlighted by the problem.

So what we need to do is just sort the array $$$b$$$, index the $$$n+1$$$ largest elements of $$$b$$$ with odd numbers and the rest with even numbers in $$$a$$$, and calculate out the lost element $$$a_2$$$.

But scarcely when the contest was only one single minute away from finishing had I reached this aha moment :(

public static void solve() throws Exception {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    long[] b = new long[2*n];
    for (int i = 0; i < 2 * n; i++) {
        b[i] = scanner.nextLong();
    }
    Arrays.sort(b);
    long lostElement = 0;
    for (int i = 0; i < n - 1; i++) {
        lostElement -= b[i];
    }
    for (int i = n - 1; i < 2 * n; i++) {
        lostElement += b[i];
    }
    System.out.print(b[2 * n - 1] + " " + lostElement + " ");
    for (int i = 0; i < n - 1; i++) {
        System.out.print(b[2 * n - i - 2] + " " + b[i] + " ");
    }
    System.out.println(b[n - 1]);
}

Again, the solutions and methods above may not be the best for the problems, so please wait for the official editorial if you take my solutions as complex ones. Though I performed like s**t in this delay-by-10-minute round, I do think problems (along with music tracks) in this round are mathematically inspiring.

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

»
15 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Koo_Pung-Kei.

»
11 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Agree, indeed for me also this contest problems especially ABC is so fun to have work onto it. Not like recently round which they struck me with geometry problems...

  • »
    »
    3 hours ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    ... for me also this contest problems especially ABC is so fun to have work onto it.

    Exactly. The problems are hard for brute force solutions but aha moment may occur after we discover mathematical sequences, and the music track given also helped when making solving attempts.

    ... Not like recently round which they struck me with geometry problems...

    I think Codeforces Round 1009 (Div. 3) is just a geometry-themed problem set, but the insights may still fail to escape algorithms (for after-D problems maybe, but I'm not sure because I don't know how to solve them). I participated in the round as well — the first 2 problems still have mathematical sequences but the third is hard enough to make discoveries LoL

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

nicely writtten, hope you keep doing this!

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks for your appreciation and I will keep making amateur editorials should I struggle through more problems than usual XD

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

The way you explained C is the best I have found till now, now things a clear , thanks.