結果

問題 No.2086 A+B問題
ユーザー umimelumimel
提出日時 2022-09-30 21:27:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,188 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 165,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 14:41:23
合計ジャッジ時間 2,315 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    string a, b;
    cin >> a >> b;

    ll na = (ll)a.size();
    ll nb = (ll)b.size();

    for(ll i=0; i<na/2; i++) swap(a[i], a[na-1-i]);
    for(ll i=0; i<nb/2; i++) swap(b[i], b[nb-1-i]);

    string c="";
    ll carry = 0;
    rep(i, min(na, nb)){
        ll x = (a[i]-'0') + (b[i]-'0') + carry;
        c += (x%10 + '0');
        carry = x/10;
    }

    for(ll i=min(na, nb); i<max(na, nb); i++){
        if(na > nb){
            ll x = (a[i]-'0') + carry;
            c += (x%10 + '0');
            carry = x/10;
        }else{
            ll x = (b[i]-'0') + carry;
            c += (x%10 + '0');
            carry = x/10;
        }
    }

    if(carry > 0) c += (carry + '0');

    ll nc = (ll)c.size();
    for(ll i=0; i<nc/2; i++) swap(c[i], c[nc-1-i]);
    cout << c << endl;
}
0