結果

問題 No.1088 A+B Problem
ユーザー 08 Phạm Phúc Bình08 Phạm Phúc Bình
提出日時 2022-03-03 04:59:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 5,139 bytes
コンパイル時間 3,909 ms
コンパイル使用メモリ 238,128 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-16 18:35:53
合計ジャッジ時間 4,549 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:132:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
  132 | const int oooo = 1e18;
      |                  ^~~~

ソースコード

diff #

/**
 ____ ____ ____ ____ 
||ú |||_ |||ò |||a ||
||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|
 
**/

#pragma GCC optimize("O3")
#pragma target("sse4")

#include<bits/stdc++.h>

using namespace std;

// Policy Based DataStructure

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

template <class A> // increasing :)
using in_ordered_set = tree<A, null_type, less<A>, rb_tree_tag, tree_order_statistics_node_update>; 

template <class A> // decreasing :)
using de_ordered_set = tree<A, null_type, greater<A>, rb_tree_tag, tree_order_statistics_node_update>;

template <class A> // smaller than or equal :)
using ms_ordered_set = tree<A, null_type, less_equal<A>, rb_tree_tag, tree_order_statistics_node_update>;

// find_by_order() -> returns an iterator to the k-th largest element (counting from zero)
// order_of_key() -> the number of items in a set that are strictly smaller than our item

//hihi
#define ll long long
#define ld long double
#define db double

//haha
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define ins insert
#define ff first
#define ss second

//huhu
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lb lower_bound // first pos >= val
#define ub upper_bound // first pos > val

//set val
#define ms0(a) memset(a, 0, sizeof(a))
#define ms_1(a) memset(a, -1, sizeof(a))
#define msinf(a) memset(a, 0x3f, sizeof(a))

// pair
#define pii pair<int,int>
#define pld pair<long double,long double>

// array
#define ar array

// vector
#define vi vector<int>
#define vld vector<long double>
#define mat vector<vector<int>>
#define vpii vector<pair<int,int>>

// FOR
#define For(i, a, b) for(int i = a; i < b; i++)
#define Ford(i, a, b) for(int i = a; i > b; i--)
#define ForE(i, a, b) for(int i = a; i <= b; i++)
#define FordE(i, a, b) for(int i = a; i >= b; i--)

//hehe
template<class T> using maxheap = priority_queue<T>;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template <class T> ostream& operator << (ostream& out, vector<T> vv) {
    out << "{";
    for(int i = 0; i < sz(vv); i++) {
        out << vv[i];
        if(i != vv.size() - 1) {
            out << ",";
        }
    }
    out << "}";
    return out;
}
template <class T> ostream& operator << (ostream& out, pair<T,T> prr) {
    out << "{" << prr.ff << "," << prr.ss << "}";
    return out;
}
template<class T> bool setmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // a = min(a, b)
template<class T> bool setmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } // a = max(a, b)
const int MOD = 1e9 + 7; // 998244353
template<class T> 
        void add(T& a, const T& b) {
            a = (a + b);
            if(a >= MOD) a -= MOD;
        }
template<class T> 
        void sub(T& a, const T& b) {
            a = (a - b);
            if(a < 0) a += MOD;
        }
// 
int dX4[] = {0, 0, 1, -1};
int dY4[] = {1, -1, 0, 0};

int dX8[] = {0, -1, -1, -1, 0, 1, 1, 1};
int dY8[] = {1, 1, 0, -1, -1, -1, 0, 1};

int ddX[] = {-1,-2, -2, -1, 1, 2, 2, 1};
int ddY[] = {-2, -1, 1, 2, 2 , 1, -1, -2};

// #define Niconiconiiiiiiii

// DEBUG
#ifdef Niconiconiiiiiiii
    #define debug(x) cout << #x << " = " << x << "\n";
#else
    #define debug(x);
#endif

// Const
const int mxN = 2e5 + 5;
const int mxX = 1e6 + 1;
const int oooo = 1e18;
const int oo = 1e9;
const char nl = '\n';
const long double eps = 1e-9;



void u_oa() {
    string a, b;
    cin >> a >> b;
    int i = sz(a) - 1, j = sz(b) - 1;
    deque<int> ans;
    int rem = 0;
    while(i >= 0 && j >= 0) {
        if((a[i] - 48) + (b[j] - 48) >= 10) {
            if(i == 0 && j == 0) {
                ans.push_front((((a[i] - 48) + (b[j] - 48))) + rem);
            } else {
               ans.push_front((((a[i] - 48) + (b[j] - 48)) % 10) + rem);
            }
            rem = 1;
            i--; j--;
        } else {
            ans.push_front((a[i] - 48) + (b[j] - 48) + rem);
            rem = 0;
            i--; j--;
        }
    }
    while(i >= 0) {
        ans.push_front((a[i] - 48) + rem);
        i--;
    }
    while(j >= 0) {
        ans.push_front((b[j] - 48 + rem));
        j--;
    }
    for(int x : ans) cout << x;
}

int main () {
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    #ifdef Niconiconiiiiiiii
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        auto starttime = chrono::high_resolution_clock::now();
    #endif
    #ifdef LAH
        freopen(".inp","r",stdin);
        freopen(".out","w",stdout);
    #endif

    int test = 1;
    // cin >> test;
    while(test--) u_oa();

    #ifdef Niconiconiiiiiiii
        auto endtime = chrono::high_resolution_clock::now();
        auto duration = chrono::duration_cast<chrono::milliseconds>(endtime - starttime).count(); 
        cout << "\n=====" << "\nUsed: " << duration << " ms\n";
    #endif
    return 0;
    //hihihaha
    // AC di ma (^-^)
    // lam on dung TLE (^-^)
    // lam on dung RTE (^-^)
    // lam on dung MLE (^-^)
    // lam on dung WA (^-^)
}

0