Submission #1020989

# Submission time Handle Problem Language Result Execution time Memory
1020989 2024-07-12T12:38:18 Z vjudge1 Kemija (COCI22_kemija) C++17
50 / 50
1 ms 600 KB
#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 freq(string s) {
	chem ret = {0};
	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;
	chem formula[2] = {{0},{0}};
	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

Main.cpp: In function 'chem freq(std::string)':
Main.cpp:13: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]
   13 |  for(int i = (s[0] < 'A') ? 1 : 0; i < s.size(); i++) {
      |                                    ~~^~~~~~~~~~
Main.cpp:14: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]
   14 |   if(i + 1 < s.size() and s[i + 1] < 'A') {
      |      ~~~~~~^~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:40: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]
   40 |  for(int i = 1; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct