We at GDG IIITA are extremely delighted to have successfully hosted AlgoArena 2025. We want to extend our heartfelt gratitude to each and every one of you for participating in AlgoArena, our flagship coding event. Your enthusiasm, dedication, and creativity have made this event a remarkable success. We hope you enjoyed solving the questions as much as we enjoyed creating them for you.
A: Squid Game
Idea:rndascode
Can you think of extending the logic for a normal stone paper scissor game to get the solution?
To solve the problem, follow these steps:
Key Observations
If Ritesh retracts his left hand (
L1
), his remaining hand (L2
) will compete against Aaryan's hands (L3
andL4
).If Ritesh retracts his right hand (
L2
), his remaining hand (L1
) will compete against Aaryan's hands (L3
andL4
).For each scenario, compare Ritesh's remaining hand with both of Aaryan's hands:
- Ritesh wins if his symbol beats Aaryan's symbol.
- Ritesh loses if Aaryan's symbol beats his.
- The result is a draw if both symbols are the same.
Decision Process
- If Ritesh can avoid losing against both of Aaryan's hands by retracting either hand, output
Left
. - If Ritesh can avoid losing by retracting only one specific hand, output
Left
orRight
, depending on the safe choice. - If both scenarios result in at least one loss, output
Impossible
.
#include <iostream>
#include <string>
using namespace std;
string determineOutcome(char r1, char a1) {
if (r1 == a1) {
return "Draw";
} else if ((r1 == 'R' && a1 == 'S') || (r1 == 'S' && a1 == 'P') || (r1 == 'P' && a1 == 'R')) {
return "Win";
} else {
return "Lose";
}
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
char rLeft = s[0];
char rRight = s[1];
char aLeft = s[2];
char aRight = s[3];
string outcomeLeft1 = determineOutcome(rRight, aLeft);
string outcomeLeft2 = determineOutcome(rRight, aRight);
string outcomeRight1 = determineOutcome(rLeft, aLeft);
string outcomeRight2 = determineOutcome(rLeft, aRight);
bool leftSafe = (outcomeLeft1 != "Lose" && outcomeLeft2 != "Lose");
bool rightSafe = (outcomeRight1 != "Lose" && outcomeRight2 != "Lose");
if (leftSafe && rightSafe) {
cout << "Left" << endl;
} else if (leftSafe) {
cout << "Left" << endl;
} else if (rightSafe) {
cout << "Right" << endl;
} else {
cout << "Impossible" << endl;
}
}
return 0;
}
B: Binary Step Down
Idea:pranavsingh0111
We need to convert all ones to zeroes .
After each operation, what changes happen to the 1's present in the string? Try writing out a few examples in binary and observe the pattern .
Look carefully at how $$$X$$$ $$$\text&$$$ $$$(-X)$$$ affects different positions .
Can any 1 except the rightmost one be changed by applying one operation?
Only the right-most 1 is converted to 0 after applying one operation. So it is easy to say that the answer to the question is simply the number of 1's in the binary representation .
But \bf{why only the right most 1 ?? }
Let $$$X$$$ be any binary string , for example —
$$$X$$$ = $$$1101.....10000$$$
then $$$(-X)$$$ will be calculated as follows —
Flipping the bits , we get — $$$0010.....01111$$$
Now adding 1 we get — $$$0010.....10000$$$
So $$$X = 1101.....10000$$$ and $$$(-X) = 0010.....10000$$$ , we can now easily see that all the bits on the left side of the right most 1 are opposite in $$$X$$$ and $$$(-X)$$$ , so $$$ X \text& (-X)$$$ will be equal to $$$0000.....10000$$$ and subtracting it will convert the rightmost $$$1$$$ to $$$0$$$ .
#include <bits/stdc++.h>
using namespace std ;
#define int long long
#define endl '\n'
void solve(){
string s ;
cin >> s ;
int n = s.size() ;
int ans = 0 ;
for(int i=0 ; i<n ; i++){
if(s[i]=='1'){
ans++ ;
}
}
cout<<ans<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1 ;
cin >> t ;
while(t--){
solve();
}
}