結果
| 問題 |
No.2086 A+B問題
|
| コンテスト | |
| ユーザー |
weaken
|
| 提出日時 | 2024-01-29 16:51:46 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,350 bytes |
| コンパイル時間 | 2,572 ms |
| コンパイル使用メモリ | 247,128 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-28 10:02:01 |
| 合計ジャッジ時間 | 3,346 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG_
#include <compe/debug.hpp>
#else
#define dump(...)
#endif
#define FastIO cin.tie(nullptr), ios_base::sync_with_stdio(false);
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define output(msg) cout << (msg) << '\n'
#define die(msg) \
do { \
cout << msg << endl; \
exit(0); \
} while (0)
#define all(k) k.begin(), k.end()
#define INFi 1 << 30
#define INFll 1LL << 60
template <typename T> bool chmax(T& a, const T& b) {
return ((a < b) ? (a = b, true) : (false));
}
template <typename T> bool chmin(T& a, const T& b) {
return ((a > b) ? (a = b, true) : false);
}
using llint = long long int;
string zero_padding(string s, int n) {
string res{s};
rep(i, n - (int)s.size()) {
res = "0" + res;
}
return res;
}
int main() {
FastIO;
string a, b;
cin >> a >> b;
if (a.size() < b.size()) {
a = zero_padding(a, (int)b.size());
} else if (a.size() > b.size()) {
b = zero_padding(b, (int)a.size());
}
dump(a, b);
int carryup{}, len = (int)a.size();
for (int i = len - 1; i >= 0; --i) {
int n = int(a[i] - '0') + int(b[i] - '0') + carryup;
carryup = 0;
if (n >= 10) carryup = 1;
a[i] = char(n % 10 + '0');
}
if (carryup == 1) {
a = "1" + a;
}
dump(a);
output(a);
}
weaken