A. Another Sanity Check, Why Not?
Idea: FazeCT
First, you have to check if $$$n$$$ is in one of the following 3 ranges: $$$48 \le n \le 57$$$, $$$65 \le n \le 90$$$, $$$97 \le n \le 122$$$.
If no, then output "Lmao".
Else, use char() to output the character associated with the number $$$n$$$.
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n; cin >> n;
if(n<48 || (n>57 && n<65) || (n>90 && n<97) || n>122) cout << "Lmao" << endl;
else cout << char(n) << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
B. Seghhhhhhhhh
Idea: Onirique
If the length of the given string s is odd, then the answer is $$$NO$$$, since adding two strings cannot do that. Otherwise, let $$$n$$$ be the length of the string. Let's go through the first half of the string, comparing whether its first and $$$\frac{n}{2} + 1$$$ characters are equal, its second and $$$\frac{n}{2} + 2$$$ characters are equal, and so on. If the characters in any pair are not equal, the answer is $$$NO$$$, otherwise — $$$YES$$$.
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for(int tc=0;tc<t;tc++) {
string s;
cin >> s;
bool ok = true;
if (s.length() % 2 == 0) {
for(int i=0;i<s.length()/2;i++)
if (s[i] != s[i + s.length() / 2])
ok = false;
} else
ok = false;
cout << (ok ? "YES" : "NO") << endl;
}
}
D. Just A Game Of Cards
Idea: FazeCT
Big Mink always lose in this game, but he can make his points maximum possible by placing the cards in a non-decreasing order, so that in each pair of cards, the point Big Mink gets is not too differ from the point Smol Mink gets.
In other words, the array should be sorted in a non-decreasing order. Then the total point Big Mink can get is the sum of even-positioned elements in that array.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int main()
{
int n; cin >> n;
vector<ll> v(n);
for(auto &x:v) cin >> x;
sort(all(v));
ll res=0;
for(int i=0;i<n;i+=2) res+=v[i];
cout << res;
}
E. Isolated Classrooms
Idea: FazeCT
Consider every connected components of the grid, take the one that has the most 'C'.
Here you can use DFS or BFS to traverse every cells of this grid.
//--------------------------------------------------------------------
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//--------------------------------------------------------------------
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> oset;
//find by order, order of key.
//usage: oset p; p.insert(x); p.order_of_key(x);
//less, less_equal.
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
const int inf=INT_MAX;
const ll infll=LLONG_MAX;
const ll mod = 1e9+7;
//--------------------------------------------------------------------
int n,m,cur;
vector <string> grid(50);
vector <vector<bool>> vis(50, vector <bool> (50,0));
vector <int> dx={0,0,1,-1};
vector <int> dy={1,-1,0,0};
bool valid(int i,int j)
{
return (i>=0 && i<n && j>=0 && j<m);
}
void dfs(int i,int j)
{
if(!valid(i,j)) return;
if(grid[i][j]=='#' || vis[i][j]) return;
vis[i][j]=1;
cur+=(grid[i][j]=='C');
for(int k=0;k<4;k++) dfs(i+dx[k],j+dy[k]);
}
void solve()
{
vector <vector<bool>> rst(50, vector <bool> (50,0));
vis=rst;
cin >> n >> m;
for(int i=0;i<n;i++) cin >> grid[i];
int res=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(!vis[i][j] && grid[i][j]=='.')
{
cur=0;
dfs(i,j);
res=max(res,cur);
}
}
}
cout << res << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc; cin >> tc;
while(tc--)
solve();
}
F. Baby Counting
Idea: Onirique
Just output a + b, nothing too special.
Remember to use Long Long though.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
ll a,b;
cin >>a>>b;
cout<<a+b<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int t;
cin >>t;
while(t--)
solve();
}
G. 266 Massacre
Idea: Onirique
The idea is simple, just count prime numbers that is not greater than $$$n$$$, then plus 1 to the solution. This can be proved mathematically, but you can also observe this from playing with small cases.
Although $$$1$$$ is not a prime number, but a pair of $$$(1, n)$$$ always have $$$GCD$$$ equals to $$$1$$$. Hence, $$$1$$$ should be added to the set.
Here, the troubles happen. Time limit doesn't allow you to calculate for each $$$n$$$ in the input. In this particular case, you will have to implement Sieve of Eratosthenes to pre-count the amount of prime numbers that is not greater than $$$n$$$ for every $$$n$$$ from $$$2$$$ to $$$10^6$$$.
Afterwards, implement a simple prefix sum to calculate the final answer.
//--------------------------------------------------------------------
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//--------------------------------------------------------------------
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> oset;
//find by order, order of key.
//usage: oset p; p.insert(x); p.order_of_key(x);
//less, less_equal.
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
const int inf=INT_MAX;
const ll infll=LLONG_MAX;
const ll mod = 1e9+7;
//--------------------------------------------------------------------
vector <int> v(1e6+1,1);
vector <int> pf(1e6+1,0);
void solve(int &t)
{
int n; cin >> n;
cout << "Case #" << t << ": " << pf[n] << endl;
t++;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
for(int i=2;i*i<=1e6;i++)
{
if(v[i]==1)
{
for(int j=i*i;j<=1e6;j+=i) v[j]=0;
}
}
int sum=0;
for(int i=1;i<=1e6;i++)
{
sum+=v[i];
pf[i]=sum;
}
int tc; cin >> tc;
int t=1;
while(tc--)
solve(t);
}
H. Bitwide XORperation
Idea: FazeCT
First, you have to bear these two XOR properties in mind:
Self-Inverse: $$$n \oplus n = 0$$$
Identity Element: $$$0 \oplus n = n$$$
Let's talk about the problem from this point. Suppose that we are going to change the number $$$a_i$$$, then the Bitwise XOR of all other elements is $$$A_i = a_1 \oplus a_2 \oplus \ldots \oplus a_{i-1} \oplus a_{i+1} \oplus \ldots \oplus a_{n-1} \oplus a_n$$$.
Here, according to Self-Inverse property of Bitwise XOR, $$$a_i$$$ should be changed to $$$A_i$$$ to get $$$0$$$ as a result of Bitwise XOR-ing every elements in the array.
In conclusion, compute minimum possible value of $$$|A_i - a_i|$$$.
//--------------------------------------------------------------------
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//--------------------------------------------------------------------
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> oset;
//find by order, order of key.
//usage: oset p; p.insert(x); p.order_of_key(x);
//less, less_equal.
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
const int inf=INT_MAX;
const ll infll=LLONG_MAX;
const ll mod = 1e9+7;
//--------------------------------------------------------------------
void solve()
{
int n; cin >> n;
vector <ll> v(n);
ll r=0;
for(auto &x:v)
{
cin >> x;
r^=x;
}
ll res=infll;
for(int i=0;i<v.size();i++) res=min(res,abs((r^v[i])-v[i]));
cout << res << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tc; cin >> tc;
while(tc--)
solve();
}
I. Crazy About Ice-Cream
Idea: FazeCT
The answer is the length of shortest stick multiplies the length of second longest stick.
The shortest stick is used to form the width of the rectangular space. Similarly, the second longest stick is used to form the length of the rectangular space.
#include <bits/stdc++.h>
using namespace std;
//--------------------------------------------------------------------
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
const int inf=INT_MAX;
const ll mod = 1e9+7;
//--------------------------------------------------------------------
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t; cin >> t;
while(t--)
{
vector <ll> v(4);
for(auto &x:v) cin >> x;
sort(all(v));
cout << ll(v[0]*v[2]) << endl;
}
}



