CSES - Aalto Competitive Programming 2024 - wk8 - Wed - Results
Submission details
Task:A TIMES B!
Sender:aalto2024i_005
Submission time:2024-10-30 16:53:59 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:12:5: error: 'vector' was not declared in this scope
   12 |     vector<int> res(n);
      |     ^~~~~~
input/code.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
input/code.cpp:12:12: error: expected primary-expression before 'int'
   12 |     vector<int> res(n);
      |            ^~~
input/code.cpp:19:13: error: 'res' was not declared in this scope
   19 |             res[i] = s;
      |             ^~~
input/code.cpp:24:9: error: 'res' was not declared in this scope
   24 |         res[i] = res[i] + c;
      |         ^~~
input/code.cpp:32:17: error: 'res' was not declared in this scope
   32 |         cout << res[i];
      |                 ^~~

Code

#include <iostream>
using namespace std;

int main()
{
    string a, b;
    cin >> a >> b;
    int k = a.size();
    int m = b.size();
    int n = k + m - 1;
    int s = 0;
    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        s = 0;
        for (int j = max(0, i - m); j < i + 1; j++) {
            if (j < k && i - j < m) {
                s += (a[j] - '0') * (b[i - j] - '0');
            }
            res[i] = s;
        }
    }
    int c = 0;
    for (int i = n - 1; i >= 0; i--) {
        res[i] = res[i] + c;
        c = res[i] / 10;
        res[i] = res[i] % 10;
    }
    if (c != 0) {
        cout << c;
    }
    for (int i = 0; i < n; i++) {
        cout << res[i];
    }
    cout << endl;
    return 0;
}