Input
The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.Output
Output “YES” or “NO”.Examplesinput
GENIUS
output
YES
input
DOCTOR
output
NO
input
IRENE
output
YES
input
MARY
output
NO
input
SMARTPHONE
output
NO
input
REVOLVER
output
YES
input
HOLMES
output
NO
input
WATSON
output
YES
Solution:
#include <bits/stdc++.h>
using namespace std;
vector<string> els = {"H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Cn","Nh","Fl","Mc","Lv","Ts","Og"};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
for (string& x : els) {
if (x.size() == 2) {
x[1] = (char) toupper(x[1]);
}
}
string s;
cin >> s;
vector<bool> dp(s.size() + 1);
dp[0] = true;
for (int i = 0; i < (int) s.size(); i++) {
if (dp[i]) {
for (string w : els) {
if (s.substr(i, w.size()) == w) {
dp[i + (int) w.size()] = true;
}
}
}
}
cout << (dp.back() ? "YES" : "NO") << '\n';
return 0;
}
Related posts:
Heavy-light decomposition
Pearls in a Row
Petr and a Combination Lock
Lowest Common Ancestor - Farach-Colton and Bender Algorithm
Ice Cream
Helga Hufflepuff's Cup
The Chocolate Spree
Pattern
The Maths Lecture
Nastya and Strange Generator
Dreamoon Likes Sequences
Finding articulation points in a graph in $O(N+M)$
New Year and Ascent Sequence
Desk Disorder
New Year Domino
Welfare State
Ordering T-Shirts
Preparing for the Contest
Solving assignment problem using min-cost-flow
Substitutes in Number
Boring Partition
Make It One
Arkady and a Nobody-men
Three Blocks Palindrome
Optimal Polygon Perimeter
Banana
Falling Blocks
Happy Line
Another One Bites The Dust
Scheduling jobs on one machine
Dating
M-numbers