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

Автор IcpcTanta, история, 13 часов назад, По-английски

Introduction

Contest #1 was an exciting competition with strong participation from multiple contestants. The contest featured four problems (A, B, C1, C2), and the results were as follows:

EyadBT achieved the first accepted solution in A, C1, and C2.

Ibrahimfostok was the first to solve B.

The fastest full completion was achieved by EyadBT (67 minutes).


Standings

Rank User Solved Penalty
1 EyadBT 4 67
2 MoamenZ 4 118
3 Mazen_Ghanayem 4 134
4 sword060 4 203
5 AhmedElseyoufi 4 207
6 mostafaabdelaal_03 4 229
7 ALFarouK 4 253
8 Ibrahimfostok 4 261
9 AliRagab313 4 262
10 AL70SSAIN 4 263

Join our group to participate in future contests and discussions: Codeforces group and Telegram group


Problem A:

Hint

Notice that the input is ignored and doesn’t affect the output.

Solution

The problem simply requires printing three predetermined answers regardless of the input provided. Even though a string is read, it is not used in any computation, and the program always outputs "ICPC TANTA", "Hassan Fathi", and "Mo Salah" in order.


Problem B:

Hint

  1. Look for the first adjacent pair where the right character is smaller than the left.
  2. If none found, check for any pair of equal adjacent characters to swap.
  3. If the string is strictly increasing, swap the last two characters as a fallback.

Solution

The approach is to perform exactly one adjacent swap that minimizes the lexicographical order. We first scan the string to find the earliest index where s[i+1] < s[i] and swap these two characters, as this immediately reduces the string’s lexicographical value. If no such pair exists (i.e., the string is non-decreasing), we then look for adjacent equal characters, and swapping them, although it doesn't change the string, still satisfies the one-swap requirement. Finally, if neither condition is met—meaning the string is strictly increasing—we swap the last two characters to ensure an operation is performed.


Problem C1:

Hint

  1. Use DFS/backtracking while marking visited cells to avoid revisiting and count path lengths accurately.
  2. Check if revisiting cells forms a cycle to leverage the full color frequency for scoring.

Solution

The solution involves performing a DFS from every unvisited cell in the grid to explore paths that can be formed by moving to adjacent cells with the same color. During the DFS, we maintain a count of the visited cells, updating the maximum score if a longer simple path is found. If the DFS detects a cycle—indicated by reaching a cell that has already been visited from the current path—then the score for that cycle is taken as the total frequency of that color in the grid. The final answer is the maximum score achieved either through a simple path or a cycle, computed by iterating over all cells and performing the DFS while ensuring that cells are marked visited appropriately to avoid reprocessing.


Problem C2:

Hint

If a cycle is found, use the full count of that color; otherwise, compute the component’s diameter via double DFS.

Solution

The solution processes the grid by exploring connected components of cells sharing the same color. For each component, it performs a DFS to mark all cells and detect if a cycle exists (i.e., a neighbor is revisited that isn’t the immediate predecessor). If a cycle is detected, the maximum score for that color is the total number of dots of that color in the grid. Otherwise, the algorithm computes the longest simple path (or "diameter") in that component using a two-phase DFS, where the first DFS finds the farthest point from an arbitrary starting cell, and the second DFS from that farthest cell determines the diameter. Finally, the answer is the maximum score obtained among all colors.

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

»
11 часов назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

It was an amazing contest .. Thanks for the authors <3

  • »
    »
    11 часов назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thanks,Great job, Ibrahim. Making it to the top 10 is no small feat—well done . Looking forward to seeing you crush it in the next contests

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

very interesting problems!, thanks you all

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

This was one of the best contests I've participated in recently. Thank you so much!