제출 #1356498

#제출 시각아이디문제언어결과실행 시간메모리
1356498goulthenMultiply (CEOI17_mul)C++20
40 / 100
444 ms580 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,a,b) for (int i = a; i >= b; i--)
#define pii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define pb push_back
#define all(v) (v).begin(), (v).end()

const int MAXN = 5e5+10;
const int INF = 1e18+10;
const int MOD = 1e9+7;

string add(string a, string b) {
    int carry = 0;
    string res;
    while(a.size()>0 && b.size() > 0) {
        int cur = (a.back()-'0') + (b.back()-'0')+carry;
        res += cur%10+'0';
        carry = cur/10;

        a.pop_back();
        b.pop_back();
    }
    if(a.size()==0) swap(a,b);
    while (a.size()>0) {
        int cur = a.back()-'0'+carry;
        carry = cur/10;
        res+=cur%10+'0';
        a.pop_back();
    }
    if(carry) res+="1";
    reverse(all(res));
    return res;
}

string mul(string a, int b) {
    string res = "0";
    while (b>0) {
        res = add(res,a);
        b--;
    }
    return res;
}

string mul(string a, string b) {
    string ans = "0";
    while(!b.empty()) {
        ans = add(mul(a, (b.back()-'0')),ans);
        b.pop_back();
        a += '0';
    }
    return ans;
}

void solve() {
    int n,m; cin >> n >> m;
    string a,b; cin >> a >> b;

    cout << mul(a,b) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
	int tt = 1;
    //cin >> tt;
    
    while(tt--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...