Tutorial for GDG CC Wing Selection 2026

Правка en3, от Kunal_Khandelwal, 2026-08-09 13:37:55

Problem A : Pentagon Orchard(Easy version)
Author : Casual_W

Hint1
Hint 2
Hint 3
Solution
Code

Problem B : Pentagon Orchard(Hard version)
Author : Casual_W

Hint 1
Hint 2
Hint 3
Solution
Code

Problem C : Helicopter Rescue
Author : Godbot

Hint 1
Hint 2
Hint 3
Solution
Code

Problem D : Bitwise Transitions
Author : Godbot

Hint 1
Hint 2
Hint 3
Solution
Code

Problem E : Score Normalization
Author : Godbot

Hint 1
Hint 2
Hint 3
Solution

Problem F : Equal Floors
Author : Its_Tarun

Hint 1
Hint 2
Hint 3
Solution
Code

Problem I : Dewansh and the Secret Numbers
Author : JAS1123

Solution
Code

Problem J : Jai's Permutation
Author : JAS1123

We construct the array starting with $$$P_1 = 1$$$. Each subsequent term $$$P_i$$$ ($$$1 \lt i \le N$$$) is formed by alternatingly applying step sizes (jumps) of $$$N$$$ and $$$N+2$$$:

$$$P_i = \vert{}N - P_{i-1}\vert{}$$$ if $$$i$$$ is odd,
$$$P_i = \vert{}(N + 2) - P_{i-1}\vert{}$$$ if $$$i$$$ is even.

Modulo $$$(N+1)$$$, notice that:
$$$N \equiv -1 \pmod{N+1}$$$
$$$N+2 \equiv +1 \pmod{N+1}$$$

2. Jump Sum Analysis ($$$L$$$):

For a contiguous block of length $$$k$$$, the jump sum $$$L_k$$$ alternates between terms of $$$N$$$ and $$$N+2$$$. The possible jump sums $$$L$$$ take two forms:

$$$\text{Type 1 (starts with } N \text{)}: N + (N+2) + N + (N+2) + \dots$$$
$$$\text{Type 2 (starts with } N+2 \text{)}: (N+2) + N + (N+2) + N + \dots$$$

For example, when $$$k = 3$$$:
$$$\text{Type 1: } N + (N+2) + N = 3N + 2$$$
$$$\text{Type 2: } (N+2) + N + (N+2) = 3N + 4$$$

In general, for a block of length $$$k$$$, $$$L = kN + (k \pm 1)$$$.

3. Parity & Impossibility Proof:

Let's analyze $$$L$$$ and $$$N+1$$$ based on the parity of $$$N$$$:

Case 1: $$$N$$$ is Even
Modulo $$$M = N + 1$$$ is odd.
Since $$$N$$$ is even, $$$kN$$$ is always even. The term $$$k + (k \pm 1) = 2k \pm 1$$$ is always odd.
Therefore, any block jump sum $$$L = kN + (k \pm 1)$$$ is always odd.

For the full array length $$$k = N$$$ (which is even), the jump sum is:
$$$L_N = \frac{N}{2} \cdot N + \frac{N}{2} \cdot (N+2) = N(N+1)$$$.

Taking this modulo $$$(N+1)$$$ gives:
$$$L_N \equiv 0 \pmod{N+1}$$$.

Because $$$L_N \equiv 0 \pmod{N+1}$$$, the prefix sum after $$$N$$$ steps loops back to $$$S_0$$$. Thus, the total array sum is divisible by $$$N+1$$$, making a valid permutation impossible for even $$$N$$$. Output -1.

Case 2: $$$N$$$ is Odd
Modulo $$$M = N + 1$$$ is even.
For the full array length $$$k = N$$$ (which is odd), the jump sum is:
$$$L_N = \left(\frac{N+1}{2}\right)N + \left(\frac{N-1}{2}\right)(N+2) = N(N+1) - 1$$$.

Taking this modulo $$$(N+1)$$$ gives:
$$$L_N \equiv -1 \equiv N \pmod{N+1} \neq 0$$$.

Since $$$L_N \not\equiv 0 \pmod{N+1}$$$, no prefix sum collides with $$$S_0$$$. All prefix sums $$$S_0, S_1, \dots, S_N$$$ remain pairwise distinct modulo $$$N+1$$$, guaranteeing a valid permutation!

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define loop(i, n) for (int i = 0; i < n; i++)
#define print_vec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
#define endl '\n'
signed main() {
    int t=1;
    // cin >> t;
    while (t--) {
        int n; cin >> n;
        int s = (n*(n+1))/2;
        if(s%(n+1)){
            vi ans(n);
            ans[0] = 1;
            for(int i=1;i<n;i++){
                if(i&1) ans[i] = abs(n-ans[i-1]);
                else ans[i] = abs(n+2-ans[i-1]);
            }
            print_vec(ans);
            cout<<endl;
        }else cout<<-1<<endl;

    }
    return 0;
}

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en22 Английский Kunal_Khandelwal 2026-08-12 07:51:07 676
en21 Английский Kunal_Khandelwal 2026-08-10 21:08:03 0 (published)
en20 Английский Kunal_Khandelwal 2026-08-10 21:07:10 10
en19 Английский Kunal_Khandelwal 2026-08-10 21:04:25 525
en18 Английский Kunal_Khandelwal 2026-08-10 20:57:32 95
en17 Английский Kunal_Khandelwal 2026-08-10 20:51:45 2485
en16 Английский Kunal_Khandelwal 2026-08-10 20:16:36 1171
en15 Английский Kunal_Khandelwal 2026-08-10 19:31:18 191
en14 Английский Kunal_Khandelwal 2026-08-10 19:25:35 208
en13 Английский Kunal_Khandelwal 2026-08-10 19:23:31 55
en12 Английский Kunal_Khandelwal 2026-08-10 19:21:58 913
en11 Английский Kunal_Khandelwal 2026-08-10 19:18:17 8819
en10 Английский Kunal_Khandelwal 2026-08-10 14:09:31 5010
en9 Английский Kunal_Khandelwal 2026-08-10 12:38:19 5837
en8 Английский Kunal_Khandelwal 2026-08-09 19:26:58 20
en7 Английский Kunal_Khandelwal 2026-08-09 19:25:06 2602
en6 Английский Kunal_Khandelwal 2026-08-09 18:17:22 5383
en5 Английский Kunal_Khandelwal 2026-08-09 14:27:06 3030
en4 Английский Kunal_Khandelwal 2026-08-09 13:45:39 1295
en3 Английский Kunal_Khandelwal 2026-08-09 13:37:55 954
en2 Английский Kunal_Khandelwal 2026-08-09 13:32:03 27700 Tiny change: '\n\n~~~~~\n#' -> '\n~~~~~\n#'
en1 Английский Kunal_Khandelwal 2026-08-09 12:48:47 546 Initial revision (saved to drafts)