Biweekly contest 3 Editorial

Revision en8, by panda_2500, 2022-12-17 08:54:20

Note from Author:

Congrats to all the Winners. Glad to see so much participation. Hope to see you all participate in the next biweekly as well. You can contact panda_2500 (Abhijit Mishra) or adityagi02 (Aditya Tyagi) for any queries related to the contest or problem discussion.

I would recommend first looking at the hints for the problem if your facing logical issue, if you are absolutely clear with logic then move on to look at the solution and the code. Efforts will be made towards making code for other languages (Python) available as well.

A — Xeros


Hint

Code(C++)

// Aur Bhai Dekhne aagaye ;) // Author: Abhijit Mishra

include <bits/stdc++.h>

using namespace std;

define nl cout << "\n"

define all(x) x.begin(), x.end()

define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

typedef long long int ll; typedef vector vi;

int main() { fast; ll t = 1; cin >> t; while (t--) { ll n; cin >> n; vi a(n); for (int i = 0; i < n; i++) { cin >> a[i]; }

if (is_sorted(all(a))) { cout << 0; }
    else
    {
        ll ans = 0;
        ll l = 0, r = n - 1;
        while (l != r)
        {
            if (a[l] == 0) { l++; }
            else if (a[r] == 1) { r--; }
            else if (a[l] == 1 && a[r] == 0)
            {
                a[l] = 0;
                a[r] = 1;
                ans++;
            }
        }
        if (is_sorted(all(a))) { cout << ans; }
    }
    nl;

}
return 0;

}

Code(Java 11)

public class Rebellion { public static void main(String[]args){

Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    while(t>0){
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0;i<n;i++) arr[i] = sc.nextInt();
        int p1 = 0;
        int p2 = n-1;
        int ans = 0;
        while(p1<p2){
            if(arr[p1] == 0){
                p1++;
                continue;
            }
            if(arr[p2] == 1){
                p2--;
                continue;
            }
            if(arr[p1] ==  1 && arr[p2] ==  0){
                ans++;
                p1++;
                p2--;
            }
        }
        System.out.println(ans);
        t--;
    }
}

} ```

B — Best Friend Game


Hints

Hint 1

Hint 2

Hint 3

Solution

Code(C++)

C — Happy New Year


Hints

Hint 1

Hint 2

Solution

Code(C++)

D — Favourite Drink


Hints

Hint 1

Hint 2

Solution

Code(C++)

E — Good number


Hints

Hint 1

Hint 2

Solution

Code(C++)

F — Punishment


Hints

Hint 1

Hint 2

Solution

Code(C++)

G — Treasure


Hints

Hint 1

Hint 2

Solution

Code(C++)

H — Count Pairs


Hints

Hint 1

Hint 2

Solution

Code(C++)

I — Transform Array


Solution

Code(C++)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en27 English adityagi02 2022-12-18 09:42:03 4366
en26 English panda_2500 2022-12-17 22:20:29 828
en25 English panda_2500 2022-12-17 22:19:27 1431 Reverted to en23
en24 English panda_2500 2022-12-17 22:18:33 1431
en23 English panda_2500 2022-12-17 21:40:25 0 (published)
en22 English panda_2500 2022-12-17 21:38:46 0 (saved to drafts)
en21 English panda_2500 2022-12-17 21:32:45 0 (published)
en20 English panda_2500 2022-12-17 21:30:43 62
en19 English panda_2500 2022-12-17 21:24:05 409
en18 English panda_2500 2022-12-17 17:54:35 4311
en17 English panda_2500 2022-12-17 17:40:38 1656
en16 English panda_2500 2022-12-17 17:29:08 3015
en15 English panda_2500 2022-12-17 17:02:14 3
en14 English panda_2500 2022-12-17 14:01:46 1215
en13 English panda_2500 2022-12-17 09:51:36 1219
en12 English panda_2500 2022-12-17 09:39:54 1038
en11 English panda_2500 2022-12-17 09:15:22 1491
en10 English panda_2500 2022-12-17 09:04:42 147
en9 English panda_2500 2022-12-17 09:02:59 551 Tiny change: 'n</spoiler' -> 'n</spoiler>\n</spoiler>\n\n</spoiler'
en8 English panda_2500 2022-12-17 08:54:20 14
en7 English panda_2500 2022-12-17 08:53:44 22
en6 English panda_2500 2022-12-17 08:52:44 1697
en5 English adityagi02 2022-12-16 20:16:36 1115 Tiny change: ' (Aditya Taygi) for an' -> ' (Aditya Tyagi) for an'
en4 English panda_2500 2022-12-16 17:33:32 6819
en3 English panda_2500 2022-12-16 17:19:00 2 Tiny change: '\n#### Note ' -> '#### Note '
en2 English panda_2500 2022-12-16 17:18:11 87
en1 English panda_2500 2022-12-16 17:08:14 9646 Initial revision (saved to drafts)