Submission #1020966

#TimeUsernameProblemLanguageResultExecution timeMemory
1020966vjudge1Kemija (COCI22_kemija)C++17
50 / 50
1 ms456 KiB
#include <bits/stdc++.h> #define fast cin.tie(0)->sync_with_stdio(0); #define int long long #define inf ((int)1e18) #define N 200005 using namespace std; typedef array <int, 26> chem; chem bos; void print(chem huh) { cout << "array:\n"; for(int i = 0; i < 2; i++) { cout << huh[i] << " "; } cout << "\n"; }; chem freq(string s) { chem ret = bos; int times = (s[0] < 'A') ? s[0] - '0' : 1; for(int i = (s[0] < 'A') ? 1 : 0; i < s.size(); i++) { if(i + 1 < s.size() and s[i + 1] < 'A') { ret[s[i] - 'A'] += times * (s[i + 1] - '0'); i++; } else { ret[s[i] - 'A'] += times; } } return ret; } chem sum(chem a, chem b) { chem ret; for(int i = 0; i < 26; i++) { ret[i] = a[i] + b[i]; } return ret; } void solve(){ string s; cin >> s; int prev = 0; for(int i = 0; i < 26; i++) { bos[i] = 0; } vector<chem> formula(2, bos); bool side = 0; s.push_back('+'); for(int i = 1; i < s.size(); i++) { if(s[i] == '+' or s[i] == '-') { string t = s.substr(prev, i - prev); chem wtf = freq(t); // print(wtf); formula[side] = sum(formula[side], wtf); prev = i + 1; } if(s[i] == '-') { i++; prev++; side = 1; } } bool yes = 1; for(int i = 0; i < 26; i++) { if(formula[0][i] != formula[1][i]) yes = 0; } if(yes) { cout << "DA\n"; } else { cout << "NE\n"; } } int32_t main(){ fast int t=1; cin >> t; while(t--) solve(); } //

Compilation message (stderr)

Main.cpp: In function 'chem freq(std::string)':
Main.cpp:22:38: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = (s[0] < 'A') ? 1 : 0; i < s.size(); i++) {
      |                                    ~~^~~~~~~~~~
Main.cpp:23:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   if(i + 1 < s.size() and s[i + 1] < 'A') {
      |      ~~~~~~^~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:52:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i = 1; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...