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;
void solve() {
int a, b, c;
cin >> a >> b >> c;
if (a + b == c) {cout << "+\n";}
else {cout << "-\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;
int x, odd = 0, even = 0;
for(int i = 0; i < n; i++)
{
cin >> x;
if(x%2 == 0)
{
even+=x;
}
else
{
odd+=x;
}
}
if(even > odd)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << 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;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int mp[26];
for (int i = 0; i < 26; i++) {
mp[i] = -1;
}
for (int i = 0; i < n; i++) {
int curr = (s[i] - 'a');
if (mp[curr] == -1) {
mp[curr] = (i % 2);
}
else {
if (mp[curr] != (i % 2)) {cout << "NO\n"; return;}
}
}
cout << "YES\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: SlavicG
Tutorial
Tutorial is loading...
Solution
#include <iostream>
using namespace std;
long long n,a[200005],q,sum=0,pref[200005],t;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>t;
while(t--)
{
sum = 0;
cin >> n >> q;
for(int i=1;i<=n;i++){
cin >> a[i];
sum+=a[i];
pref[i]=pref[i-1];
pref[i]+=a[i];
}
for(int i = 0; i < q; i++){
long long l,r,k;
cin >> l >> r >> k;
long long ans = pref[n]-(pref[r]-pref[l-1])+k*(r-l+1);
if(ans%2==1){
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}
}
Idea: SlavicG
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,a[2000005],pref[2000005];
int32_t main(){
//CODE_START;
#ifdef LOCAL
//ifstream cin("input.txt");
#endif
cin>>t;
while(t--){
cin>>n;
for(ll i=1;i<=n;i++)
{
cin>>a[i];
pref[i]=pref[i-1]+a[i];
}
ll l=1,r=n,ans=0;
while(l<=r){
ll mid=(l+r)/2;
cout<<"? "<<(mid-l+1)<<' ';
for(ll i=l;i<=mid;i++)
{
cout<<i<<' ';
}
cout<<endl<<flush;
ll x=0;
cin>>x;
if(x==pref[mid]-pref[l-1]){
l=mid+1;
}else {
r=mid-1;
ans=mid;
}
}
cout<<"! "<<ans<<endl<<flush;
}
}
Idea: mesanu
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n, m, x1, y1, x2, y2;
string d_string;
cin >> n >> m >> x1 >> y1 >> x2 >> y2;
x1--;x2--;y1--;y2--;
cin >> d_string;
int d = (d_string[0] == 'U' ? 1+(d_string[1] == 'R' ? 2 : 0) : 0+(d_string[1] == 'R' ? 2 : 0));
bool vis[n][m][4];
memset(vis, false, sizeof(vis));
int i = x1, j = y1;
int bounces = 0;
while(!vis[i][j][d])
{
if(i == x2 && j == y2){cout << bounces << endl; return;}
int na = 0;
if(d%2 == 1 && i == 0){d-=1;na++;}
if(d%2 == 0 && i == n-1){d+=1;na++;}
if(d >= 2 && j == m-1){d-=2;na++;}
if(d < 2 && j == 0){d+=2;na++;}
bounces+=min(1, na);
if(vis[i][j][d])
{
break;
}
vis[i][j][d] = true;
if(d%2 == 1){i--;}else{i++;}
if(d >= 2){j++;}else{j--;}
}
cout << -1 << endl;
}
int32_t main(){
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
1807G1 - Subsequence Addition (Easy Version)
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
void solve() {
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(all(a));
if(a[0] != 1) {
cout << "NO\n";
return;
}
vector<int> dp(5005, 0);
dp[1] = 1;
for(int i = 1; i < n; ++i) {
if(!dp[a[i]]) {
cout << "NO\n";
return;
}
for(int j = 5000; j >= a[i]; --j) {
dp[j] |= dp[j - a[i]];
}
}
cout << "YES\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
1807G2 - Subsequence Addition (Hard Version)
Idea: flamestorm
Tutorial
Tutorial is loading...
Solution
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
void solve() {
int n; cin >> n;
vector<int> a(n);
for(int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(all(a));
if(a[0] != 1) {
cout << "NO\n";
return;
}
long long sum = a[0];
for(int i = 1; i < n; ++i) {
if(sum < a[i]) {
cout << "NO\n";
return;
}
sum += a[i];
}
cout << "YES\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}