Thank you for participating!
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
string alph = "abc";
void solve() {
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < 3; i++) {
cnt += (s[i] != alph[i]);
}
cout << (cnt <= 2 ? "YES\n" : "NO\n");
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int> a(n);
int ans = 1;
for(int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
a[0]++;
for(int i = 0; i < n; i++)
{
ans*=a[i];
}
cout << ans << endl;
}
int32_t main(){
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
int score[10][10] = {
{1,1,1,1,1,1,1,1,1,1},
{1,2,2,2,2,2,2,2,2,1},
{1,2,3,3,3,3,3,3,2,1},
{1,2,3,4,4,4,4,3,2,1},
{1,2,3,4,5,5,4,3,2,1},
{1,2,3,4,5,5,4,3,2,1},
{1,2,3,4,4,4,4,3,2,1},
{1,2,3,3,3,3,3,3,2,1},
{1,2,2,2,2,2,2,2,2,1},
{1,1,1,1,1,1,1,1,1,1}
};
void solve() {
int ans = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
char c;
cin >> c;
if (c == 'X') {ans += score[i][j];}
}
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
void solve() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int res = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'B') {
res++; i += k - 1;
}
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
void solve() {
int n;
long long x;
cin >> n >> x;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long lo = 0, hi = 2'000'000'007;
while (lo < hi) {
long long mid = lo + (hi - lo + 1) / 2;
long long tot = 0;
for (int i = 0; i < n; i++) {
tot += max(mid - a[i], 0LL);
}
if (tot <= x) {lo = mid;}
else {hi = mid - 1;}
}
cout << lo << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int N = 200'000;
int n, k;
int a[N+5], h[N+5], pref[N+5], length[N+5];
bool get(int dist)
{
bool found = false;
for(int i = 0; i < n-dist+1; i++)
{
if(length[i] < dist){continue;}
int sum = pref[i+dist]-pref[i];
if(sum <= k)
{
found = true;
break;
}
}
return found;
}
void solve()
{
pref[0] = 0;
cin >> n >> k;
for(int i = 0; i < n; i++)
{
cin >> a[i];
pref[i+1] = pref[i]+a[i];
}
for(int i = 0; i < n; i++)
{
cin >> h[i];
}
length[n-1] = 1;
for(int i = n-2; i >= 0; i--)
{
if(h[i]%h[i+1] == 0)
{
length[i] = length[i+1]+1;
}
else
{
length[i] = 1;
}
}
int l = 1, r = N;
while(l <= r)
{
int mid = (l+r)/2;
if(get(mid))
{
l = mid+1;
}
else
{
r = mid-1;
}
}
cout << r << endl;
}
int main() {
int t = 1;
cin >> t;
while (t--)
{
solve();
}
}
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200'007;
const int MOD = 1'000'000'007;
void solve() {
string s;
cin >> s;
int n = s.length(), cnt = 0;
bool all = (s[0] == 'B' || s[n - 1] == 'B');
for (int i = 0; i < n - 1; i++) {
if (s[i] == s[i + 1] && s[i] == 'B') {all = true;}
}
vector<int> lens;
int curr = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'A') {curr++;}
else {
if (curr != 0) {lens.push_back(curr);}
curr = 0;
}
}
if (curr != 0) {lens.push_back(curr);}
sort(lens.begin(), lens.end());
if (lens.empty()) {cout << 0 << '\n'; return;}
int tot = 0;
if (all) {tot += lens[0];}
for (int i = 1; i < lens.size(); i++) {
tot += lens[i];
}
cout << tot << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> adj[N];
vector<bool> vis(N);
int entry_node = -1;
vector<int> path;
bool dfs1(int u, int p)
{
vis[u] = true;
for(auto v : adj[u])
{
if(v != p && vis[v])
{
entry_node = v;
return true;
}
else if(v != p && !vis[v])
{
if(dfs1(v, u))
{
return true;
}
}
}
return false;
}
int dfs2(int u)
{
vis[u] = true;
int distbruh = N;
for(auto v : adj[u])
{
if(v == entry_node)
{
return 1;
}
if(!vis[v])
{
int dist = dfs2(v)+1;
distbruh = min(dist, distbruh);
}
}
return distbruh;
}
void solve()
{
int n, a, b;
cin >> n >> a >> b;
for(int i = 0; i < n; i++)
{
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs1(b, -1);
vis.assign(n+1, false);
int distMarcel = N, distValeriu = 0;
if(entry_node == a)
{
distMarcel = 0;
}
else
{
distMarcel = dfs2(a);
}
vis.assign(n+1, false);
if(entry_node == b)
{
distValeriu = 0;
}
else
{
distValeriu = dfs2(b);
}
if(distValeriu < distMarcel)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
for(int i = 1; i <= n; i++)
{
adj[i].clear();
vis[i] = false;
}
}
int32_t main(){
int t = 1;
cin >> t;
while (t--) {
solve();
}
}