Gửi bài giải

Điểm: 5,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 1G
Input: stdin
Output: stdout

Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Output Only, Pascal, PyPy, Python, Scratch, TEXT

Cho hai số nguyên dương ~A~ và ~B~ (~1 \le A, B \le 5000~). Hãy tính ~A + B~.

SAMPLE INPUT

1 2

SAMPLE OUTPUT

3

Bình luận

Hãy đọc nội quy trước khi bình luận.



  • -1
    ndhquan  đã bình luận lúc 27, Tháng 7, 2026, 7:16

    đáp án:

    #include <iostream>
    #include <memory>
    #include <variant>
    #include <type_traits>
    
    namespace Ultra {
    namespace Meta {
    
    template<int N>
    struct Factorial {
        static constexpr long long value = N * Factorial<N - 1>::value;
    };
    
    template<>
    struct Factorial<0> {
        static constexpr long long value = 1;
    };
    
    template<typename Derived>
    class Printable {
    public:
        void print() const {
            static_cast<const Derived*>(this)->printImpl();
        }
    };
    
    } // namespace Meta
    
    namespace Core {
    
    class Expression {
    public:
        virtual long long evaluate() const = 0;
        virtual ~Expression() = default;
    };
    
    class Number : public Expression,
                   public Meta::Printable<Number> {
    private:
        long long value;
    public:
        explicit Number(long long v) : value(v) {}
    
        long long evaluate() const override {
            return value;
        }
    
        void printImpl() const {
            std::cout << value;
        }
    };
    
    class Add : public Expression {
    private:
        std::shared_ptr<Expression> lhs;
        std::shared_ptr<Expression> rhs;
    public:
        Add(std::shared_ptr<Expression> l,
            std::shared_ptr<Expression> r)
            : lhs(std::move(l)), rhs(std::move(r)) {}
    
        long long evaluate() const override {
            return lhs->evaluate() + rhs->evaluate();
        }
    };
    
    class Evaluator {
    private:
        Evaluator() = default;
    public:
        static Evaluator& instance() {
            static Evaluator e;
            return e;
        }
    
        long long run(const Expression& expr) {
            return expr.evaluate();
        }
    };
    
    } // namespace Core
    
    namespace Utility {
    
    // Variant wrapper for absolutely no reason
    using Input = std::variant<int, long long>;
    
    template<typename T>
    long long convert(const T& x) {
        if constexpr(std::is_same_v<T, int>)
            return static_cast<long long>(x);
        else
            return x;
    }
    
    }
    
    }
    
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    
        using namespace Ultra;
    
        Utility::Input A, B;
    
        long long x, y;
        std::cin >> x >> y;
    
        A = x;
        B = y;
    
        auto getValue = [](const Utility::Input& v) {
            return std::visit([](auto&& arg) {
                return Utility::convert(arg);
            }, v);
        };
    
        auto left = std::make_shared<Core::Number>(getValue(A));
        auto right = std::make_shared<Core::Number>(getValue(B));
    
        Core::Add expression(left, right);
    
        [[maybe_unused]] constexpr auto useless = Meta::Factorial<10>::value;
    
        std::cout << Core::Evaluator::instance().run(expression);
    
        return 0;
    }
    

  • -4
    BeTraiHocCode138  đã bình luận lúc 10, Tháng 6, 2026, 8:46 sửa 3

    Code danh cho newbie (sieu than thien 100% :3)

    #include<any>
    
    #include<array>
    
    #include<atomic>
    
    #include<algorithm>
    
    #include<bit>
    
    #include<bitset>
    
    #include<barrier>
    
    #include<ctime>
    
    #include<cmath>
    
    #include<cfenv>
    
    #include<cctype>
    
    #include<cfloat>
    
    #include<cerrno>
    
    #include<cwchar>
    
    #include<cstdio>
    
    #include<chrono>
    
    #include<complex>
    
    #include<csignal>
    
    #include<compare>
    
    #include<climits>
    
    #include<cstdint>
    
    #include<cstddef>
    
    #include<csetjmp>
    
    #include<clocale>
    
    #include<cstdlib>
    
    #include<cassert>
    
    #include<cstring>
    
    #include<cwctype>
    
    #include<cstdarg>
    
    #include<charconv>
    
    #include<concepts>
    
    #include<cinttypes>
    
    #include<condition_variable>
    
    #include<deque>
    
    #include<expected>
    
    #include<exception>
    
    #include<execution>
    
    #include<format>
    
    #include<future>
    
    #include<fstream>
    
    #include<filesystem>
    
    #include<functional>
    
    #include<forward_list>
    
    #include<ios>
    
    #include<iosfwd>
    
    #include<istream>
    
    #include<iomanip>
    
    #include<iostream>
    
    #include<iterator>
    
    #include<initializer_list>
    
    #include<list>
    
    #include<latch>
    
    #include<limits>
    
    #include<map>
    
    #include<mutex>
    
    #include<memory>
    
    #include<memory_resource>
    
    #include<numeric>
    
    #include<numbers>
    
    #include<ostream>
    
    #include<optional>
    
    #include<queue>
    
    #include<regex>
    
    #include<ratio>
    
    #include<ranges>
    
    #include<random>
    
    #include<set>
    
    #include<span>
    
    #include<stack>
    
    #include<string>
    
    #include<sstream>
    
    #include<stdfloat>
    
    #include<strstream>
    
    #include<streambuf>
    
    #include<semaphore>
    
    #include<stdexcept>
    
    #include<spanstream>
    
    #include<stacktrace>
    
    #include<stop_token>
    
    #include<string_view>
    
    #include<shared_mutex>
    
    #include<system_error>
    
    #include<source_location>
    
    #include<tuple>
    
    #include<thread>
    
    #include<typeinfo>
    
    #include<typeindex>
    
    #include<type_traits>
    
    #include<utility>
    
    #include<unordered_set>
    
    #include<unordered_map>
    
    #include<vector>
    
    #include<variant>
    
    #include<valarray>
    
    using namespace std;
    
    int a,b;
    
    int main(){
    
    iosbase::syncwith_stdio(false);
    
    cin.tie(nullptr);
    
    cin >> a >> b;
    
    cout << a + b;
    
    return 0;
    
    }