Submission details
Task:Laskutoimitus
Sender:Metabolix
Submission time:2025-12-20 18:47:24 +0200
Language:C++ (C++20)
Status:READY
Result:5
Feedback
groupverdictscore
#1ACCEPTED5
#20
#30
#40
#50
#60
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 6details
#2ACCEPTED0.01 s1, 2, 6details
#3ACCEPTED0.01 s1, 2, 3, 4, 5, 6details
#40.00 s2, 6details
#50.00 s2, 6details
#60.00 s2, 3, 4, 5, 6details
#70.01 s6details
#80.01 s6details
#90.01 s3, 4, 5, 6details
#100.01 s4, 6details
#110.01 s4, 6details
#120.01 s5, 6details
#130.01 s5, 6details

Compiler report

input/code.cpp: In function 'int stomodi(std::string)':
input/code.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < s.size(); ++i) {
      |                     ~~^~~~~~~~~~
input/code.cpp: In function 'int laske(std::string)':
input/code.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int i = 0; i < s.size(); ++i) {
      |                         ~~^~~~~~~~~~
input/code.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < l.size(); ++i) {
      |                     ~~^~~~~~~~~~
input/code.cpp:48...

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1000000007;

int stomodi(string s) {
    ll ret = 0;
    for (int i = 0; i < s.size(); ++i) {
        ret = ((10 * ret) + (s[i] - '0')) % mod;
    }
    return (int)ret;
}

int laske(string s) {
    vector<vector<string>> l;
    if (1) {
        l.push_back({""});
        string luku;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == '+') {
                l.push_back({""});
                continue;
            }
            if (s[i] == '*') {
                l.rbegin()->push_back("");
                continue;
            }
            *l.rbegin()->rbegin() += s[i];
        }
        for (auto& p: l) {
            while (p.size() && p.rbegin()->size() == 0) {
                p.pop_back();
            }
        }
        while (l.size() && l.rbegin()->size() == 0) {
            l.pop_back();
        }
    }

    vector<vector<int>> modl;
    ll res = 0;
    for (int i = 0; i < l.size(); ++i) {
        ll mul = 1;
        for (int j = 0; j < l[i].size(); ++j) {
            mul = (mul * stomodi(l[i][j])) % mod;
        }
        res = (res + mul) % mod;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    if (s.size() <= 100) {
        ll result = 0;
        for (int a = 0; a < s.size(); ++a) {
            for (int b = a+1; b <= s.size(); ++b) {
                auto t = s.substr(a, b-a);
                if (t[0] == '+' || t[0] == '*' || t[t.size()-1] == '+' || t[t.size()-1] == '*') {
                    continue;
                }
                int tmp = laske(t);
                result = (result + tmp) % mod;
            }
        }
        cout << result << endl;
        return 0;
    }
    return 0;
}

Test details

Test 1

Group: 1, 2, 6

Verdict: ACCEPTED

input
*3*7*5+67*2*7*12+38*4+9+2+1+45...

correct output
665527462

user output
665527462

Test 2

Group: 1, 2, 6

Verdict: ACCEPTED

input
84149523195388144+1*8*5*1722+5...

correct output
572374284

user output
572374284

Test 3

Group: 1, 2, 3, 4, 5, 6

Verdict: ACCEPTED

input
347358248955243114242997746491...

correct output
823495931

user output
823495931

Test 4

Group: 2, 6

Verdict:

input
+4976829*6+5+9*21+4*889+6*7+4*...

correct output
503712700

user output
(empty)

Feedback: Output is shorter than expected

Test 5

Group: 2, 6

Verdict:

input
862+83782+493135426+3152859674...

correct output
624304680

user output
(empty)

Feedback: Output is shorter than expected

Test 6

Group: 2, 3, 4, 5, 6

Verdict:

input
297736662651354417265929591745...

correct output
625284593

user output
(empty)

Feedback: Output is shorter than expected

Test 7

Group: 6

Verdict:

input
+9+1+8+92*761+68*983*1+7*1+1*2...

correct output
947469815

user output
(empty)

Feedback: Output is shorter than expected

Test 8

Group: 6

Verdict:

input
97831833*7+4229897789494398634...

correct output
173934151

user output
(empty)

Feedback: Output is shorter than expected

Test 9

Group: 3, 4, 5, 6

Verdict:

input
777551563653223263644973172313...

correct output
278364064

user output
(empty)

Feedback: Output is shorter than expected

Test 10

Group: 4, 6

Verdict:

input
+481+4+66+2+26+7+5+97+6+4+3+14...

correct output
244847224

user output
(empty)

Feedback: Output is shorter than expected

Test 11

Group: 4, 6

Verdict:

input
+8858717+53+6927+314+742552843...

correct output
928369840

user output
(empty)

Feedback: Output is shorter than expected

Test 12

Group: 5, 6

Verdict:

input
*7*75*59*7*9*74*4*18211*31*1*7...

correct output
219382651

user output
(empty)

Feedback: Output is shorter than expected

Test 13

Group: 5, 6

Verdict:

input
73171*3438*9*34165158853*375*7...

correct output
451362612

user output
(empty)

Feedback: Output is shorter than expected