結果

問題 No.1492 01文字列と転倒
ユーザー CyanmondCyanmond
提出日時 2021-04-30 22:04:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,858 bytes
コンパイル時間 1,855 ms
コンパイル使用メモリ 189,880 KB
最終ジャッジ日時 2025-01-21 03:07:39
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:110:21: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
  110 |   const int N = read();
      |                 ~~~~^~
In file included from /usr/include/unistd.h:1217,
                 from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/13/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:116,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/unistd.h:26:1: note: declared here
   26 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~
main.cpp:111:21: error: too few arguments to function ‘ssize_t read(int, void*, size_t)’
  111 |   const int M = read();  // M is prime
      |                 ~~~~^~
/usr/include/x86_64-linux-gnu/bits/unistd.h:26:1: note: declared here
   26 | read (int __fd, void *__buf, size_t __nbytes)
      | ^~~~

ソースコード

diff #

#include "bits/stdc++.h"
#pragma region cscpptemp
// require at least C++17 to compile
using llint = long long int;
template <class T>
using Heap = std::priority_queue<T>;
template <class T>
using RevHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

// ex. for (const int i : range(a, b)) ... loop [a, b)
template <class T, class = std::enable_if_t<std::is_signed_v<T>>>
class range {
  struct range_iterator {
    T itr;
    constexpr range_iterator(const int pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { ++itr; }
    constexpr bool operator!=(const range_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr T operator*() const noexcept { return itr; }
  };

 public:
  constexpr range(const T first_, const T last_) noexcept
      : first(first_), last(last_) {}
  constexpr range_iterator begin() const noexcept { return first; }
  constexpr range_iterator end() const noexcept { return last; }

 private:
  const range_iterator first, last;
};

// ex. for (const int i : range(a, b)) ... revloop [a, b]
template <class T, class = std::enable_if_t<std::is_signed_v<T>>>
class revrange {
  struct revrange_iterator {
    T itr;
    constexpr revrange_iterator(const int pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { --itr; }
    constexpr bool operator!=(const revrange_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr T operator*() const noexcept { return itr; }
  };

 public:
  constexpr revrange(const T first_, const T last_) noexcept
      : first(first_), last(last_ - 1) {}
  constexpr revrange_iterator begin() const noexcept { return first; }
  constexpr revrange_iterator end() const noexcept { return last; }

 private:
  const revrange_iterator first, last;
};

// ex. rec_lambda([](auto&& f, int n) -> int {return n < 1 ? 1 : f(--n); })
template <class F>
class rec_lambda {
 public:
  constexpr rec_lambda(F&& f_) : f(std::forward<F>(f_)) {}
  template <class... Args>
  constexpr auto operator()(Args&&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }

 private:
  F f;
};

// ex. const int N = read()
struct read {
  template <class T>
  operator T() {
    T ret;
    std::cin >> ret;
    return ret;
  }
};

// ex. chmax(a, b) ... a = max(a, b)
template <class T>
constexpr void chmax(T& a, const T b) noexcept {
  if (a < b) a = b;
}
template <class T>
constexpr void chmin(T& a, const T b) noexcept {
  if (a > b) a = b;
}

// ex. ceildiv(a, b) ... ceil(a / b)
template <class T, class = std::enable_if_t<std::is_integral_v<T>>>
constexpr T ceildiv(const T dividend, const T divisor) {
  return (dividend + divisor - 1) / divisor;
}

// ex. mk_vec(a, b, c, v) ... 3D vector size: [a][b][c] init value: v
template <class T>
auto mk_vec(const int n, const T value) {
  return std::vector(n, value);
}
template <class... Args>
auto mk_vec(const int n, Args... args) {
  return std::vector(n, mk_vec(args...));
}
#pragma endregion

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  const int N = read();
  const int M = read();  // M is prime
  // 0sum <= 1sum (all i)
  std::vector DP(N + 1, std::vector(N + 1, std::vector(N * N + 1, 0)));
  /* (0, 1) = (a, b)
   * invnum = k
   * DP[a + 1][b]
   */
  DP[0][0][0] = 1;
  for (const int a : range(0, N + 1))
    for (const int b : range(0, a + 1))
      for (const int k : range(0, N * N + 1)) {
        if (a != N and k + b <= N * N) {
          DP[a + 1][b][k + b] += DP[a][b][k];
          if (DP[a + 1][b][k + b] >= M) DP[a + 1][b][k + b] -= M;
        }
        if (a > b) {
          DP[a][b + 1][k] += DP[a][b][k];
          if (DP[a][b + 1][k] >= M) DP[a][b + 1][k] -= M;
        }
      }
  for (const int i : range(0, N * N + 1)) std::cout << DP[N][N][i] << '\n';
  // .............
  return 0;
}
0