Editorial for Indexing (INDX12)

Practice
Div-2 Contest
Div-1 Contest
In case the contest did not have two separate pages for Div-1 and Div-2, you can delete one of these above lines.

CAKEWALK

Math,Array.

PROBLEM:

You are given a string of characters and you have to find the Sum of the indexes of each character (according to lexicographical order). check if the sum of all indexes is even or odd.

If the sum of all index values is even then print “YES” (without quotes). else print “NO”(without quotes).

NOTE:- The string contains only lowercase characters.

QUICK EXPLANATION:

You have to calculate sum of all index values of the alphabets in the string (i.e form 1 to 26) All alphabets.

EXPLANATION:

You have to calculate sum of all index values of the alphabets in the string (i.e form 1 to 26) All alphabets. let’s take an example and understand.
eg:- abhishek
in the above example the sum of all index values is equal to 63
(1 + 2 + 8 + 9 + 19 + 8 + 5 + 11) so the answer is NO.

After calculating the sum of all indexes you have to check the sum value is even or odd.
if the sum is even the you have to print “YES” (without quotes). else print “NO”.

SOLUTIONS:

Setter's Solution

#include <bits/stdc++.h>
const long long SZ = 4e3 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define pll pair<ll, ll>
#define vi vector
#define vs vector
#define vpl vector
#define qi queue
#define si set
#define map map<ll, ll>
#define umap unordered_map<ll, ll>
#define fi first
#define se second
#define sz(x) (ll)x.size()
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define Max(a,b) ((a > b) ? a : b)
#define Min(a,b) ((a < b) ? a : b)
#define ci(X) ll X; cin>>X
#define cii(X, Y) ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z) ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) ll W, X, Y, Z; cin>>W>>X>>Y>>Z
#define co cout<<
#define in cin>>
#define Jivan_ka_asli_aadhar_to_prem_hai_na ll ___T; cin>>___T; while (___T-- > 0)
#define Code_Wode_mai_kya_rakha_hai ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 1e18
#define ed endl
#define abhi(i, n) for(ll i = 0; i < (n); i++)
#define abhi1(i, n) for(ll i = 1; i <= (n); i++)
#define abhi2(i, l, r) for(ll i = l; i < (r); i++)
#define rabhi(i, l, r) for(ll i = l; i >= (r); i–)
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X, V) memset((X), 1, sizeof((X)))
#define ms2(X, V) memset((X), 1, sizeof((X)))
#define flv(X, V) fill(all((X)), V)
#define gcd(a,b) __gcd(a,b)
using namespace std;
ll prmod(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = (ans * a) % MOD;
b = b / 2;
a = (a * a) % MOD;
}
return ans;
}
int pri(ll n)
{
int flag=0;
for(ll i = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
return 1;
}
else
{
return 0;
}
}
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
{
int sum=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]==‘a’)
{
sum=sum+1;
}
else if(s[i]==‘b’)
{
sum=sum+2;
}
else if(s[i]==‘c’)
{
sum=sum+3;
}
else if(s[i]==‘d’)
{
sum=sum+4;
}
else if(s[i]==‘e’)
{
sum=sum+5;
}
else if(s[i]==‘f’)
{
sum=sum+6;
}
else if(s[i]==‘g’)
{
sum=sum+7;
}
else if(s[i]==‘h’)
{
sum=sum+8;
}
else if(s[i]==‘i’)
{
sum=sum+9;
}
else if(s[i]==‘j’)
{
sum=sum+10;
}
else if(s[i]==‘k’)
{
sum=sum+11;
}
else if(s[i]==‘l’)
{
sum=sum+12;
}
else if(s[i]==‘m’)
{
sum=sum+13;
}
else if(s[i]==‘n’)
{
sum=sum+14;
}
else if(s[i]==‘o’)
{
sum=sum+15;
}
else if(s[i]==‘p’)
{
sum=sum+16;
}
else if(s[i]==‘q’)
{
sum=sum+17;
}
else if(s[i]==‘r’)
{
sum=sum+18;
}
else if(s[i]==‘s’)
{
sum=sum+19;
}
else if(s[i]==‘t’)
{
sum=sum+20;
}
else if(s[i]==‘u’)
{
sum=sum+21;
}
else if(s[i]==‘v’)
{
sum=sum+22;
}
else if(s[i]==‘w’)
{
sum=sum+23;
}
else if(s[i]==‘x’)
{
sum=sum+24;
}
else if(s[i]==‘y’)
{
sum=sum+25;
}
else if(s[i]==‘z’)
{
sum=sum+26;
}
}
//cout<<sum<<" “;
if(sum%2==0)
{
cout<<“YES”<<”\n";
}
else
{
cout<<“NO”<<“\n”;
}
}
int main()
{
Code_Wode_mai_kya_rakha_hai;
{
}
}

Tester's Solution

#include <bits/stdc++.h>
const long long SZ = 4e3 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define pll pair<ll, ll>
#define vi vector
#define vs vector
#define vpl vector
#define qi queue
#define si set
#define map map<ll, ll>
#define umap unordered_map<ll, ll>
#define fi first
#define se second
#define sz(x) (ll)x.size()
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define Max(a,b) ((a > b) ? a : b)
#define Min(a,b) ((a < b) ? a : b)
#define ci(X) ll X; cin>>X
#define cii(X, Y) ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z) ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) ll W, X, Y, Z; cin>>W>>X>>Y>>Z
#define co cout<<
#define in cin>>
#define Jivan_ka_asli_aadhar_to_prem_hai_na ll ___T; cin>>___T; while (___T-- > 0)
#define Code_Wode_mai_kya_rakha_hai ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 1e18
#define ed endl
#define abhi(i, n) for(ll i = 0; i < (n); i++)
#define abhi1(i, n) for(ll i = 1; i <= (n); i++)
#define abhi2(i, l, r) for(ll i = l; i < (r); i++)
#define rabhi(i, l, r) for(ll i = l; i >= (r); i–)
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X, V) memset((X), 1, sizeof((X)))
#define ms2(X, V) memset((X), 1, sizeof((X)))
#define flv(X, V) fill(all((X)), V)
#define gcd(a,b) __gcd(a,b)
using namespace std;
ll prmod(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = (ans * a) % MOD;
b = b / 2;
a = (a * a) % MOD;
}
return ans;
}
int pri(ll n)
{
int flag=0;
for(ll i = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
return 1;
}
else
{
return 0;
}
}
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
{
int sum=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]==‘a’)
{
sum=sum+1;
}
else if(s[i]==‘b’)
{
sum=sum+2;
}
else if(s[i]==‘c’)
{
sum=sum+3;
}
else if(s[i]==‘d’)
{
sum=sum+4;
}
else if(s[i]==‘e’)
{
sum=sum+5;
}
else if(s[i]==‘f’)
{
sum=sum+6;
}
else if(s[i]==‘g’)
{
sum=sum+7;
}
else if(s[i]==‘h’)
{
sum=sum+8;
}
else if(s[i]==‘i’)
{
sum=sum+9;
}
else if(s[i]==‘j’)
{
sum=sum+10;
}
else if(s[i]==‘k’)
{
sum=sum+11;
}
else if(s[i]==‘l’)
{
sum=sum+12;
}
else if(s[i]==‘m’)
{
sum=sum+13;
}
else if(s[i]==‘n’)
{
sum=sum+14;
}
else if(s[i]==‘o’)
{
sum=sum+15;
}
else if(s[i]==‘p’)
{
sum=sum+16;
}
else if(s[i]==‘q’)
{
sum=sum+17;
}
else if(s[i]==‘r’)
{
sum=sum+18;
}
else if(s[i]==‘s’)
{
sum=sum+19;
}
else if(s[i]==‘t’)
{
sum=sum+20;
}
else if(s[i]==‘u’)
{
sum=sum+21;
}
else if(s[i]==‘v’)
{
sum=sum+22;
}
else if(s[i]==‘w’)
{
sum=sum+23;
}
else if(s[i]==‘x’)
{
sum=sum+24;
}
else if(s[i]==‘y’)
{
sum=sum+25;
}
else if(s[i]==‘z’)
{
sum=sum+26;
}
}
//cout<<sum<<" “;
if(sum%2==0)
{
cout<<“YES”<<”\n";
}
else
{
cout<<“NO”<<“\n”;
}
}
int main()
{
Code_Wode_mai_kya_rakha_hai;
{
}
}

Editorialist's Solution

#include <bits/stdc++.h>
const long long SZ = 4e3 + 7;
const long long inf = 1e18;
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
long long opnmbr = 1;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define pll pair<ll, ll>
#define vi vector
#define vs vector
#define vpl vector
#define qi queue
#define si set
#define map map<ll, ll>
#define umap unordered_map<ll, ll>
#define fi first
#define se second
#define sz(x) (ll)x.size()
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define Max(a,b) ((a > b) ? a : b)
#define Min(a,b) ((a < b) ? a : b)
#define ci(X) ll X; cin>>X
#define cii(X, Y) ll X, Y; cin>>X>>Y
#define ciii(X, Y, Z) ll X, Y, Z; cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) ll W, X, Y, Z; cin>>W>>X>>Y>>Z
#define co cout<<
#define in cin>>
#define Jivan_ka_asli_aadhar_to_prem_hai_na ll ___T; cin>>___T; while (___T-- > 0)
#define Code_Wode_mai_kya_rakha_hai ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 1e18
#define ed endl
#define abhi(i, n) for(ll i = 0; i < (n); i++)
#define abhi1(i, n) for(ll i = 1; i <= (n); i++)
#define abhi2(i, l, r) for(ll i = l; i < (r); i++)
#define rabhi(i, l, r) for(ll i = l; i >= (r); i–)
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X, V) memset((X), 1, sizeof((X)))
#define ms2(X, V) memset((X), 1, sizeof((X)))
#define flv(X, V) fill(all((X)), V)
#define gcd(a,b) __gcd(a,b)
using namespace std;
ll prmod(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = (ans * a) % MOD;
b = b / 2;
a = (a * a) % MOD;
}
return ans;
}
int pri(ll n)
{
int flag=0;
for(ll i = 2; i <= n / 2; ++i)
{
if(n % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
return 1;
}
else
{
return 0;
}
}
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
{
int sum=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]==‘a’)
{
sum=sum+1;
}
else if(s[i]==‘b’)
{
sum=sum+2;
}
else if(s[i]==‘c’)
{
sum=sum+3;
}
else if(s[i]==‘d’)
{
sum=sum+4;
}
else if(s[i]==‘e’)
{
sum=sum+5;
}
else if(s[i]==‘f’)
{
sum=sum+6;
}
else if(s[i]==‘g’)
{
sum=sum+7;
}
else if(s[i]==‘h’)
{
sum=sum+8;
}
else if(s[i]==‘i’)
{
sum=sum+9;
}
else if(s[i]==‘j’)
{
sum=sum+10;
}
else if(s[i]==‘k’)
{
sum=sum+11;
}
else if(s[i]==‘l’)
{
sum=sum+12;
}
else if(s[i]==‘m’)
{
sum=sum+13;
}
else if(s[i]==‘n’)
{
sum=sum+14;
}
else if(s[i]==‘o’)
{
sum=sum+15;
}
else if(s[i]==‘p’)
{
sum=sum+16;
}
else if(s[i]==‘q’)
{
sum=sum+17;
}
else if(s[i]==‘r’)
{
sum=sum+18;
}
else if(s[i]==‘s’)
{
sum=sum+19;
}
else if(s[i]==‘t’)
{
sum=sum+20;
}
else if(s[i]==‘u’)
{
sum=sum+21;
}
else if(s[i]==‘v’)
{
sum=sum+22;
}
else if(s[i]==‘w’)
{
sum=sum+23;
}
else if(s[i]==‘x’)
{
sum=sum+24;
}
else if(s[i]==‘y’)
{
sum=sum+25;
}
else if(s[i]==‘z’)
{
sum=sum+26;
}
}
//cout<<sum<<" “;
if(sum%2==0)
{
cout<<“YES”<<”\n";
}
else
{
cout<<“NO”<<“\n”;
}
}
int main()
{
Code_Wode_mai_kya_rakha_hai;