Submission #899422

# Submission time Handle Problem Language Result Execution time Memory
899422 2024-01-06T06:47:02 Z HamzaT Kemija (COCI22_kemija) C++14
50 / 50
1 ms 604 KB
//struct Edge {int u, v, weight;bool operator<(Edge const& other) {return weight < other.weight;}};
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define sp ' '
#define pb push_back
#define ar for(int i=1;i<=n;i++)
using namespace std;
ll t=1;
const ll N=3e5+100;
ll n,m,q,k;
ll a[N],b[N],c[N];
void solve()
{
    string s;cin>>s;
    map<char,int>mp;int indx=1;
    vector<string>v1,v2;string x="";
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='+'){v1.push_back(x);x="";continue;}
        if(s[i]=='-'){i++;indx=i;break;}
        x+=s[i];
    }
    if(x.size()){v1.push_back(x);}x="";
    for(int i=indx+1;i<s.size();i++)
    {

        if(s[i]=='+'){v2.push_back(x);x="";continue;}
        if(s[i]=='-'){i++;indx=i;break;}
        x+=s[i];
    }
    ll num;
    if(x.size()){v2.push_back(x);}x="";
    for(auto i:v1)
    {
        num=0;
        x=i;indx=0;
        //2H2O
        string x2="";
        while(x[indx]<'A'||x[indx]>'Z'){x2+=x[indx];indx++;}
        for(auto j:x2){num*=10;num+=j-'0';}
        if(num==0){num=1;}
        for(int j=indx;j<x.size();j++)
        {
            if(j+1<x.size()&&x[j+1]>='A'&&x[j+1]<='Z')
            {
                mp[x[j]]+=num;continue;
            }
            else if(j+1<x.size()&&(x[j+1]<'A'||x[j+1]>'Z'))
            {
                ll num2=0;
                x2="";
                int indx2=j+1;
                while(indx2<x.size()&&(x[indx2]<'A'||x[indx2]>'Z')){x2+=x[indx2];indx2++;}
                for(auto k:x2){num2*=10;num2+=k-'0';}
                mp[x[j]]+=num*num2;
                j=indx2-1;
            }
            else{mp[x[j]]+=num;}
        }
    }
    //for(auto i:mp){cout<<i.first<<" "<<i.second<<endl;}
     for(auto i:v2)
    {
        num=0;
        x=i;indx=0;
        //2H2O
        string x2="";
        while(x[indx]<'A'||x[indx]>'Z'){x2+=x[indx];indx++;}
        for(auto j:x2){num*=10;num+=j-'0';}
        if(num==0){num=1;}
        for(int j=indx;j<x.size();j++)
        {
            if(j+1<x.size()&&x[j+1]>='A'&&x[j+1]<='Z')
            {
                mp[x[j]]-=num;continue;
            }
            else if(j+1<x.size()&&(x[j+1]<'A'||x[j+1]>'Z'))
            {
                ll num2=0;
                x2="";
                int indx2=j+1;
                while(indx2<x.size()&&(x[indx2]<'A'||x[indx2]>'Z')){x2+=x[indx2];indx2++;}
                for(auto k:x2){num2*=10;num2+=k-'0';}
                mp[x[j]]-=num*num2;
                j=indx2-1;
            }
            else{mp[x[j]]-=num;}
        }
    }
    for(auto i:mp){if(i.second!=0){cout<<"NE"<<endl;return;}}
    cout<<"DA"<<endl;return;
}
int main()
{
    //freopen("shell.in", "r", stdin);
   // freopen("shell.out", "w", stdout);
    ios::sync_with_stdio(NULL);
    cin.tie(NULL);cout.tie(NULL);
      cin>>t;
    while(t--){solve();}
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<s.size();i++)
      |                 ~^~~~~~~~~
Main.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=indx+1;i<s.size();i++)
      |                      ~^~~~~~~~~
Main.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for(int j=indx;j<x.size();j++)
      |                        ~^~~~~~~~~
Main.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             if(j+1<x.size()&&x[j+1]>='A'&&x[j+1]<='Z')
      |                ~~~^~~~~~~~~
Main.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             else if(j+1<x.size()&&(x[j+1]<'A'||x[j+1]>'Z'))
      |                     ~~~^~~~~~~~~
Main.cpp:54:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |                 while(indx2<x.size()&&(x[indx2]<'A'||x[indx2]>'Z')){x2+=x[indx2];indx2++;}
      |                       ~~~~~^~~~~~~~~
Main.cpp:72:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for(int j=indx;j<x.size();j++)
      |                        ~^~~~~~~~~
Main.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if(j+1<x.size()&&x[j+1]>='A'&&x[j+1]<='Z')
      |                ~~~^~~~~~~~~
Main.cpp:78:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             else if(j+1<x.size()&&(x[j+1]<'A'||x[j+1]>'Z'))
      |                     ~~~^~~~~~~~~
Main.cpp:83:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |                 while(indx2<x.size()&&(x[indx2]<'A'||x[indx2]>'Z')){x2+=x[indx2];indx2++;}
      |                       ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 464 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 344 KB Output is correct
2 Correct 0 ms 344 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 464 KB Output is correct
6 Correct 1 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 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 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 468 KB Output is correct
27 Correct 1 ms 344 KB Output is correct