답안 #704216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704216 2023-03-02T00:40:03 Z willychan Kemija (COCI22_kemija) C++14
50 / 50
1 ms 256 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
string s;
bool is_num(char a){
	return (a-'0'>=0 && a-'0'<=9);
}
vector<int> get(int l,int r){
	vector<int> ans(26);
	fill(ans.begin(),ans.end(),0);
	int all = 1;
	if(is_num(s[l])){
		all = s[l]-'0';
		l++;
	}
	int cur = 0;
	int cnt = 0;
	for(int i=l;i<=r;i++){
		if(!is_num(s[i])){
			ans[cur]+=all*cnt;
			cur = s[i]-'A';
			cnt=1;
		}else{
			cnt=s[i]-'0';
		}
	}
	ans[cur]+=all*cnt;
	return ans;
}

vector<int> parse(int l,int r){
	vector<int> ans(26,0);
	int rl = l;
	vector<int> temp(26,0);
	for(int i=l;i<=r;i++){
		if(s[i]=='+'){
			temp = get(rl,i-1);
			rl = i+1;
			for(int i=0;i<26;i++) ans[i]+=temp[i];
		}
	}
	temp = get(rl,r);
	for(int i=0;i<26;i++) ans[i]+=temp[i];
	return ans;
}



void solve(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='-'){
			vector<int> a = parse(0,i-1);	
			vector<int> b= parse(i+2,s.size()-1);
			//for(auto i:a) cout<<i<<" ";
			//cout<<"\n";
			//for(auto i:b) cout<<i<<" ";
			//cout<<"\n";
			for(int i=0;i<26;i++){
				if(a[i]!=b[i]){
					cout<<"NE\n";
					return ;
				}
			}
			cout<<"DA\n";
		}
	}


}


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t;cin>>t;
	while(t--){
		solve();
	}

	return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i=0;i<s.size();i++){
      |              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct