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 method 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>
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();
}



