結果

問題 No.1198 お菓子配り-1
ユーザー ooaiu
提出日時 2025-07-24 13:24:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 14,729 bytes
コンパイル時間 3,532 ms
コンパイル使用メモリ 281,364 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-24 13:24:07
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function ‘void fastio::Printer::flush()’:
main.cpp:421:14: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  421 |         write(fd, buf, pos);
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
using u8 = uint8_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

using namespace std;
template <class F> class y_combinator {
    F f;

   public:
    y_combinator(F&& f) : f(std::forward<F>(f)) {}
    template <class... Args> auto operator()(Args&&... args) const { return f(*this, std::forward<Args>(args)...); }
};
using ll = long long;
using ld = long double;
template <class T, class U = std::less<T>> using prique = std::priority_queue<T, std::vector<T>, U>;
template <class T> T floor(T a, T b) noexcept { return a / b - (a % b && (a ^ b) < 0); }
template <class T> T ceil(T a, T b) noexcept { return floor(a + b - 1, b); }
template <class T> bool chmin(T& x, const T& y) noexcept { return (x > y ? x = y, true : false); }
template <class T> bool chmax(T& x, const T& y) noexcept { return (x < y ? x = y, true : false); }
#define overload4(a, b, c, d, e, ...) e
#define rep1(a) for (long long _i = 0; _i < (a); _i++)
#define rep2(i, a) for (long long i = 0; i < (a); i++)
#define rep3(i, a, b) for (long long i = (a); i < (b); i++)
#define rep4(i, a, b, c) for (long long i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i, a, b, c) for (long long i = (a); i > (b); i += (c))
#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
#define pb push_back
#ifndef LOCAL
#define debug(...)
#endif

namespace type_traits {

template <class T>
using is_signed_int =
    std::integral_constant<bool, (std::is_integral<T>::value && std::is_signed<T>::value) || std::is_same<T, i128>::value>;
template <class T>
using is_unsigned_int =
    std::integral_constant<bool, (std::is_integral<T>::value && std::is_unsigned<T>::value) || std::is_same<T, u128>::value>;
template <class T>
using is_int = std::integral_constant<bool, is_signed_int<T>::value || is_unsigned_int<T>::value>;
template <class T>
using make_signed_int = typename std::conditional<
    std::is_same<T, i128>::value || std::is_same<T, u128>::value,
    std::common_type<i128>,
    std::make_signed<T>>::type;
template <class T>
using make_unsigned_int = typename std::conditional<
    std::is_same<T, i128>::value || std::is_same<T, u128>::value,
    std::common_type<u128>,
    std::make_unsigned<T>>::type;

template <class T, class = void> struct is_range : std::false_type {};
template <class T>
struct is_range<
    T,
    decltype(std::begin(std::declval<typename std::add_lvalue_reference<T>::type>()),
             std::end(std::declval<typename std::add_lvalue_reference<T>::type>()),
             (void)0)> : std::true_type {};

template <class T, bool = is_range<T>::value>
struct range_rank : std::integral_constant<std::size_t, 0> {};
template <class T>
struct range_rank<T, true>
    : std::integral_constant<std::size_t,
                             range_rank<typename T::value_type>::value + 1> {};

template <std::size_t size> struct int_least {
    static_assert(size <= 128, "size must be less than or equal to 128");

    using type = typename std::conditional<
        size <= 8,
        std::int_least8_t,
        typename std::conditional<
            size <= 16,
            std::int_least16_t,
            typename std::conditional<
                size <= 32,
                std::int_least32_t,
                typename std::conditional<size <= 64, std::int_least64_t, i128>::type>::type>::type>::type;
};

template <std::size_t size> using int_least_t = typename int_least<size>::type;

template <std::size_t size> struct uint_least {
    static_assert(size <= 128, "size must be less than or equal to 128");

    using type = typename std::conditional<
        size <= 8,
        std::uint_least8_t,
        typename std::conditional<
            size <= 16,
            std::uint_least16_t,
            typename std::conditional<
                size <= 32,
                std::uint_least32_t,
                typename std::conditional<size <= 64, std::uint_least64_t, u128>::type>::type>::type>::type;
};

template <std::size_t size> using uint_least_t = typename uint_least<size>::type;

template <class T>
using double_size_int = int_least<std::numeric_limits<T>::digits * 2 + 1>;
template <class T> using double_size_int_t = typename double_size_int<T>::type;
template <class T>
using double_size_uint = uint_least<std::numeric_limits<T>::digits * 2>;
template <class T> using double_size_uint_t = typename double_size_uint<T>::type;

template <class T>
using double_size =
    typename std::conditional<is_signed_int<T>::value, double_size_int<T>, double_size_uint<T>>::type;
template <class T> using double_size_t = typename double_size<T>::type;

}  // namespace type_traits

#include <unistd.h>
namespace fastio {
constexpr size_t buf_size = 1 << 17;

template <std::size_t decimal_precision = 16>
class Scanner {
   private:
    template <class, class = void> struct has_scan : std::false_type {};
    template <class T>
    struct has_scan<T, decltype(std::declval<T>().scan(std::declval<Scanner&>()), (void)0)> : std::true_type {};
    int fd;
    int idx, sz;
    bool state;
    std::array<char, buf_size + 1> buffer;
    inline char cur() {
        if (idx == sz) load();
        if (idx == sz) {
            state = false;
            return '\0';
        }
        return buffer[idx];
    }
    inline void next() {
        if (idx == sz) load();
        if (idx == sz) return;
        ++idx;
    }

   public:
    inline void load() {
        int len = sz - idx;
        if (idx < len) return;
        std::memcpy(buffer.begin(), buffer.begin() + idx, len);
        sz = len + read(fd, buffer.data() + len, buf_size - len);
        buffer[sz] = 0;
        idx = 0;
    }

    Scanner(int fd) : fd(fd), idx(0), sz(0), state(true) {}
    Scanner(FILE* fp) : fd(fileno(fp)), idx(0), sz(0), state(true) {}

    inline char scan_char() {
        if (idx == sz) load();
        return idx == sz ? '\0' : buffer[idx++];
    }

    Scanner ignore(int n = 1) {
        if (idx + n > sz) load();
        idx += n;
        return *this;
    }

    inline void discard_space() {
        if (idx == sz) load();
        while (('\t' <= buffer[idx] && buffer[idx] <= '\r') ||
               buffer[idx] == ' ') {
            if (++idx == sz) load();
        }
    }
    void scan(char& a) {
        discard_space();
        a = scan_char();
    }
    void scan(bool& a) {
        discard_space();
        a = scan_char() != '0';
    }
    void scan(std::string& a) {
        discard_space();
        a.clear();
        while (cur() != '\0' && (buffer[idx] < '\t' || '\r' < buffer[idx]) &&
               buffer[idx] != ' ') {
            a += scan_char();
        }
    }
    template <class T, typename std::enable_if<type_traits::is_signed_int<T>::value && !has_scan<T>::value>::type* = nullptr>
    void scan(T& a) {
        discard_space();
        if (buffer[idx] == '-') {
            ++idx;
            if (idx + 40 > sz &&
                (idx == sz || ('0' <= buffer[sz - 1] && buffer[sz - 1] <= '9')))
                load();
            a = 0;
            while ('0' <= buffer[idx] && buffer[idx] <= '9') {
                a = a * 10 - (buffer[idx++] - '0');
            }
        } else {
            if (idx + 40 > sz && '0' <= buffer[sz - 1] && buffer[sz - 1] <= '9')
                load();
            a = 0;
            while ('0' <= buffer[idx] && buffer[idx] <= '9') {
                a = a * 10 + (buffer[idx++] - '0');
            }
        }
    }
    template <class T, typename std::enable_if<type_traits::is_unsigned_int<T>::value && !has_scan<T>::value>::type* = nullptr>
    void scan(T& a) {
        discard_space();
        if (idx + 40 > sz && '0' <= buffer[sz - 1] && buffer[sz - 1] <= '9')
            load();
        a = 0;
        while ('0' <= buffer[idx] && buffer[idx] <= '9') {
            a = a * 10 + (buffer[idx++] - '0');
        }
    }
    template <class T, typename std::enable_if<std::is_floating_point<T>::value && !has_scan<T>::value>::type* = nullptr>
    void scan(T& a) {
        discard_space();
        bool sgn = false;
        if (cur() == '-') {
            sgn = true;
            next();
        }
        a = 0;
        while ('0' <= cur() && cur() <= '9') {
            a = a * 10 + cur() - '0';
            next();
        }
        if (cur() == '.') {
            next();
            T n = 0, d = 1;
            for (int i = 0; '0' <= cur() && cur() <= '9' && i < (int)decimal_precision; ++i) {
                n = n * 10 + cur() - '0';
                d *= 10;
                next();
            }
            while ('0' <= cur() && cur() <= '9') next();
            a += n / d;
        }
        if (sgn) a = -a;
    }

   private:
    template <std::size_t i, class... Args> void scan(std::tuple<Args...>& a) {
        if constexpr (i < sizeof...(Args)) {
            scan(std::get<i>(a));
            scan<i + 1, Args...>(a);
        }
    }

   public:
    template <class... Args> void scan(std::tuple<Args...>& a) {
        scan<0, Args...>(a);
    }
    template <class T, class U> void scan(std::pair<T, U>& a) {
        scan(a.first);
        scan(a.second);
    }
    template <class T, typename std::enable_if<type_traits::is_range<T>::value && !has_scan<T>::value>::type* = nullptr>
    void scan(T& a) {
        for (auto&& i : a) scan(i);
    }
    template <class T, typename std::enable_if<has_scan<T>::value>::type* = nullptr>
    void scan(T& a) {
        a.scan(*this);
    }

    void operator()() {}
    template <class Head, class... Args>
    void operator()(Head& head, Args&... args) {
        scan(head);
        operator()(args...);
    }

    template <class T> Scanner& operator>>(T& a) {
        scan(a);
        return *this;
    }

    explicit operator bool() const { return state; }

    friend Scanner& getline(Scanner& scan, std::string& a) {
        a.erase();
        char c;
        if ((c = scan.scan_char()) == '\n' || c == '\0') return scan;
        a += c;
        while ((c = scan.scan_char()) != '\n' && c != '\0') a += c;
        scan.state = true;
        return scan;
    }
};

Scanner<> scan(0);

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

class Printer {
    template <class, class = void>
    struct has_print : std::false_type {};
    template <class T>
    struct has_print<T, decltype(std::declval<T>().print(std::declval<Printer&>()), (void)0)> : std::true_type {};

    static constexpr std::size_t TMP_SIZE = 1 << 7;
    char buf[buf_size], tmp[TMP_SIZE];
    int fd;
    std::size_t pos = 0, decimal_precision;

    void wt_char(char ch) {
        buf[pos++] = ch;
        if (pos == buf_size) flush();
    }

    template <class T, typename std::enable_if<type_traits::is_int<T>::value && !has_print<T>::value>::type* = nullptr>
    void wt_integer(T x) {
        char* p = tmp + TMP_SIZE - 1;
        bool sgn = false;
        if (x < 0) {
            sgn = true;
            x = -x;
        }
        while (x >= 10000) {
            std::memcpy(p -= 4, pre.num[x % 10000], 4);
            x /= 10000;
        }
        if (x >= 1000) {
            memcpy(p -= 4, pre.num[x], 4);
        } else if (x >= 100) {
            memcpy(p -= 3, pre.num[x] + 1, 3);
        } else if (x >= 10) {
            memcpy(p -= 2, pre.num[x] + 2, 2);
        } else {
            *--p = pre.num[x][3];
        }
        if (sgn) *--p = '-';
        std::size_t len = (tmp + TMP_SIZE - 1) - p;
        if (len >= buf_size - pos) flush();
        std::memcpy(buf + pos, p, len);
        pos += len;
    }

    template <std::size_t I = 0, class Tuple>
    void wt_tuple(const Tuple& t) {
        if constexpr (I < std::tuple_size<Tuple>::value) {
            if (I > 0) wt_char(' ');
            wt(std::get<I>(t));
            wt_tuple<I + 1>(t);
        }
    }

   public:
    Printer(int fd) : fd(fd), pos(0), decimal_precision(16) {}
    Printer(FILE* fp) : fd(fileno(fp)), pos(0), decimal_precision(16) {}
    ~Printer() { flush(); }

    void wt(char ch) { wt_char(ch); }
    void wt(bool b) { wt_char(char(b + '0')); }
    void wt(const char* a) {
        for (; *a != '\0'; a++) wt_char(*a);
    }
    void wt(const std::string& s) {
        for (char ch : s) wt_char(ch);
    }

    template <class T, typename std::enable_if<type_traits::is_int<T>::value && !has_print<T>::value>::type* = nullptr>
    void wt(const T& x) { wt_integer(x); }

    template <class T, typename std::enable_if<std::is_floating_point<T>::value && !has_print<T>::value>::type* = nullptr>
    void wt(const T& x) {
        std::ostringstream oss;
        oss << std::fixed << std::setprecision(decimal_precision) << x;
        wt(oss.str());
    }

    template <class T, typename std::enable_if<type_traits::is_range<T>::value && !has_print<T>::value>::type* = nullptr>
    void wt(const T& a) {
        for (auto it = a.begin(); it != a.end(); it++) {
            if (it != a.begin()) {
                wt_char(' ');
            }
            wt(*it);
        }
    }

    template <class... Args> void wt(const std::tuple<Args...>& t) { wt_tuple<>(t); }

    template <class T, class U> void wt(const std::pair<T, U>& p) {
        wt(p.first);
        wt(' ');
        wt(p.second);
    }

    template <class T, typename std::enable_if<has_print<T>::value>::type* = nullptr>
    void wt(const T& a) { a.print(*this); }

    void flush() {
        write(fd, buf, pos);
        pos = 0;
    }

    void operator()() {}

    template <class Head, class... Tails>
    void operator()(const Head& head, const Tails&... tails) {
        wt(head);
        wt(' ');
        (*this)(tails...);
    }

    template <class T>
    Printer& operator<<(const T& a) {
        wt(a);
        return *this;
    }

    Printer& operator<<(Printer& (*func)(Printer&)) {
        return func(*this);
    }
};
Printer emit(1);

inline Printer& endl(Printer& os) {
    os.wt('\n');
    os.flush();
    return os;
}

inline Printer& flush(Printer& os) {
    os.flush();
    return os;
}

}  // namespace fastio
using fastio::emit, fastio::endl, fastio::flush, fastio::scan;

int main() {
    i128 N;
    scan >> N;
    if (N == 1) {
        cout << -1 << "\n";
    } else if (N & 1) {
        cout << 1 << "\n";
    } else if (N == 4) {
        cout << -1 << "\n";
    } else if(N % 4 == 0){
        cout << 1 << "\n";
    } else {
        cout << -1 << "\n";
    }
}
0