結果

問題 No.864 四方演算
ユーザー Arumakan1727Arumakan1727
提出日時 2019-08-16 22:13:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,414 bytes
コンパイル時間 1,394 ms
コンパイル使用メモリ 162,968 KB
最終ジャッジ日時 2023-10-26 02:46:54
合計ジャッジ時間 1,725 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In instantiation of 'void outl(Args&& ...) [with Args = {long int&}]':
main.cpp:137:9:   required from here
main.cpp:64:41: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'std::tuple<long int>')
   64 | inline void outl(Args&&... args) { cout << make_tuple(std::forward<Args>(args)...) << "\n"; }
      |                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:108:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:108:36: note:   no known conversion for argument 1 from 'std::tuple<long int>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:117:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::

ソースコード

diff #

#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          x.begin(), x.end()
#define SIZE(x)         static_cast<i64>(x.size())
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#define let             const auto

#ifdef DBG
#define trace(...) _internal::_trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
inline i64  sigma(i64 n)                    { return n * (n + 1) >> 1; }
inline i64  divup(i64 a, i64 b)             { return (a + b - 1) / b; }
inline bool inner(i64 a, i64 low, i64 high) { return (low <= a && a < high); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace _internal { // {{{
    template<size_t> struct _Uint{};
    template<class Tuple>
        ostream& _print_tuple(ostream &out, const Tuple &t, _Uint<1>) {
            return out << std::get< std::tuple_size<Tuple>::value - 1 >(t);
        }
    template<class Tuple, size_t Index>
        ostream& _print_tuple(ostream &out, const Tuple &t, _Uint<Index>) {
            out << std::get< std::tuple_size<Tuple>::value - Index >(t) << ' ';
            return _print_tuple(out, t, _Uint<Index-1>());
        }
    template <class T>
        void _trace(const char *s, T&& x) {
            clog << '{';
            while(*s != '\0') clog << *(s++);
            clog << ":" << setw(3) << x << '}' << endl;
        }
    template <class Head, class... Tail>
        void _trace(const char *s, Head&& head, Tail&&... tail) {
            clog << '{';
            while(*s != ',') clog << *(s++);
            clog << ":" << setw(3) << head << "}, ";
            for (++s; !isgraph(*s); ++s);
            _trace(s, std::forward<Tail>(tail)...);
        }
} // }}}

template<class T>
inline void input(T &x) { cin >> x; }

template<class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

template<class... Args>
inline void outl(Args&&... args) { cout << make_tuple(std::forward<Args>(args)...) << "\n"; }

ostream& operator<< (ostream &out, ostream&) { return out; }

template<class T>
ostream& operator<< (ostream &out, const vector<T> &vec) {
    rep(i, vec.size()) out << vec[i] << " \n"[i+1 == vec.size()];
    return out;
}

template<class T, class U>
ostream& operator<< (ostream &out, const pair<T, U> &p) {
    return out << p.first << ' ' << p.second;
}

template<class... Types>
ostream& operator<< (ostream &out, const tuple<Types...> &t) {
    return out << _internal::_print_tuple(out, t, _internal::_Uint<sizeof...(Types)>());
}

template<class Itr>
ostream& print(Itr begin, Itr end, const string &separator = " ", ostream &out = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) out << *begin << separator;
    out << *rbegin;
    return out;
}
// }}} End Header

// Returns n divisors ORDER BY ASC.
vector<i64> getDivisors(i64 n) // {{{
{
    vector<i64> ret;
    i64 i = 1;
    for (i = 1; i * i < n; ++i) {
        if (n % i == 0) {
            ret.emplace_back(i);
            ret.emplace_back(n / i);
        }
    }
    if (i * i == n) ret.emplace_back(i);
    return ret;
} // }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    VAR(i64, N, K);

    let divisors = getDivisors(K);

    const auto f = [&](i64 n) -> i64{
        i64 X = N;
        chmin(X, n);
        if (n % 2) {
            let mid = n / 2 + 1;
            if (X >= mid) return (X - mid) * 2 + 1;
            else return 0;
        } else {
            let mid = n / 2;
            if (X >= mid) return (X - mid) * 2;
            else return 0;
        }
    };

    // trace(N, f(1), f(2), f(3), f(4));

    i64 res = 0;
    for (let x : divisors) {
        let y = K / x;
        res += f(x-1) * f(y-1);
    }

    outl(res);

    return 0;
}
0