Submission #792202

# Submission time Handle Problem Language Result Execution time Memory
792202 2023-07-24T17:29:35 Z cig32 Kemija (COCI22_kemija) C++17
50 / 50
1 ms 724 KB
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
#define int int
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) { // bigmod
    if(p==0) return 1;
    int r = bm(b, p/2);
    if(p&1) return (((r*r) % MOD) * b) % MOD;
    return (r*r) % MOD;
}
int inv(int b) { // modinv
    return bm(b, MOD-2);
}
int f[MAXN];
int nCr(int n, int r) { // nCr main function, requires precomputation function
    int ans = f[n]; ans *= inv(f[r]); ans %= MOD;
    ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() { // factorials for nCr, function MUST BE CALLED
    f[0] = 1;
    for(int i=1; i<MAXN; i++) f[i] = (f[i-1] * i) % MOD;
}
void solve(int tc) {
  string str;
  cin >> str;
  int lcnt[26], rcnt[26];
  for(int i=0; i<26; i++) lcnt[i] = rcnt[i] = 0;
  string l, r;
  for(int i=0; i<str.size(); i++) {
    if(str[i] == '-') {
      i += 2;
      while(i < str.size()) {
        r += str[i];
        i++;
      }
      break;
    }
    l += str[i];
  }
  vector<string> vl, vr;
  string u;
  for(int i=0; i<l.size(); i++) {
    if(l[i] == '+') {
      vl.push_back(u);
      u = "";
      continue;
    }
    u += l[i];
  }
  if(u != "") {
    vl.push_back(u);
    u = "";
  }
  for(int i=0; i<r.size(); i++) {
    if(r[i] == '+') {
      vr.push_back(u);
      u = "";
      continue;
    }
    u += r[i];
  }
  if(u != "") {
    vr.push_back(u);
    u = "";
  }
  for(int i=0; i<vl.size(); i++) {
    int mul = 1;
    if(isdigit(vl[i][0])) {
      mul = vl[i][0] - '0';
      string uwu = vl[i].substr(1, vl[i].size() - 1);
      vl[i] = uwu;
    }
    for(int j=0; j<vl[i].size(); j++) {
      if(j+1 < vl[i].size() && isdigit(vl[i][j+1])) {
        lcnt[vl[i][j] - 'A'] += mul * (vl[i][j+1] - '0');
        j++;
      }
      else {
        lcnt[vl[i][j] - 'A'] += mul;
      }
    }
  }
  for(int i=0; i<vr.size(); i++) {
    int mul = 1;
    if(isdigit(vr[i][0])) {
      mul = vr[i][0] - '0';
      string uwu = vr[i].substr(1, vr[i].size() - 1);
      vr[i] = uwu;
    }
    for(int j=0; j<vr[i].size(); j++) {
      if(j+1 < vr[i].size() && isdigit(vr[i][j+1])) {
        rcnt[vr[i][j] - 'A'] += mul * (vr[i][j+1] - '0');
        j++;
      }
      else {
        rcnt[vr[i][j] - 'A'] += mul;
      }
    }
  }
  for(int i=0; i<26; i++) {
    if(lcnt[i] != rcnt[i]) {
      cout << "NE\n"; return;
    }
  }
  cout << "DA\n";
}
int32_t main(){
  precomp();
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}  

Compilation message

Main.cpp: In function 'void solve(int)':
Main.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   for(int i=0; i<str.size(); i++) {
      |                ~^~~~~~~~~~~
Main.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |       while(i < str.size()) {
      |             ~~^~~~~~~~~~~~
Main.cpp:47:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0; i<l.size(); i++) {
      |                ~^~~~~~~~~
Main.cpp:59:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i=0; i<r.size(); i++) {
      |                ~^~~~~~~~~
Main.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=0; i<vl.size(); i++) {
      |                ~^~~~~~~~~~
Main.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int j=0; j<vl[i].size(); j++) {
      |                  ~^~~~~~~~~~~~~
Main.cpp:79:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       if(j+1 < vl[i].size() && isdigit(vl[i][j+1])) {
      |          ~~~~^~~~~~~~~~~~~~
Main.cpp:88:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for(int i=0; i<vr.size(); i++) {
      |                ~^~~~~~~~~~
Main.cpp:95:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int j=0; j<vr[i].size(); j++) {
      |                  ~^~~~~~~~~~~~~
Main.cpp:96:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |       if(j+1 < vr[i].size() && isdigit(vr[i][j+1])) {
      |          ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 712 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 712 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 712 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 712 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 712 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 708 KB Output is correct
27 Correct 1 ms 724 KB Output is correct