답안 #341378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341378 2020-12-29T15:22:44 Z phathnv Multiply (CEOI17_mul) C++11
40 / 100
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 12000;
const int INF = 1e9;

int n, m, a[N], b[N], res[N];

void toArray(string &str, int a[]){
    reverse(str.begin(), str.end());
    int base = 1, cur = 0;
    for(char ch : str){
        a[cur] += (ch - '0') * base;
        base *= 10;
        if (base == 1e9){
            cur++;
            base = 1;
        }
    }
}

void readInput(){
    string sA, sB;
    cin >> m >> n;
    cin >> sA >> sB;
    toArray(sA, a);
    toArray(sB, b);
}

void solve(){
    m = (m + 8) / 9;
    n = (n + 8) / 9;
    int base = 1e9;
    for(int i = 0; i < m; i++){
        int carry = 0;
        for(int j = 0; j < n; j++){
            ll sum = carry + res[i + j] + (ll) a[i] * b[j];
            res[i + j] = sum % base;
            carry = sum / base;
        }
        res[i + n] = carry;
    }

    int sz = m + n;
    while (res[sz] == 0 && sz > 0)
        sz--;

    cout << res[sz] << setw(9) << setfill('0');
    for(int i = sz - 1; i >= 0; i--)
        cout << res[i];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    readInput();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -