結果

問題 No.616 へんなソート
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-12-16 11:24:00
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 692 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 55,704 KB
最終ジャッジ日時 2024-04-27 02:30:35
合計ジャッジ時間 648 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:8:25: error: ‘powl’ was not declared in this scope
    8 | constexpr int mod = int(powl(10, 9)) + 7;
      |                         ^~~~
main.cpp:9:1: error: ‘vector’ does not name a type
    9 | vector<vector<int>> dp;
      | ^~~~~~
main.cpp: In function ‘int f(int, int)’:
main.cpp:13:14: error: ‘dp’ was not declared in this scope
   13 |   int &res = dp[n][k];
      |              ^~
main.cpp: In function ‘int main()’:
main.cpp:34:3: error: ‘dp’ was not declared in this scope
   34 |   dp.assign(n+1, vector<int>(k+1, -1));
      |   ^~
main.cpp:34:18: error: ‘vector’ was not declared in this scope
   34 |   dp.assign(n+1, vector<int>(k+1, -1));
      |                  ^~~~~~
main.cpp:5:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    4 | #include <cassert>
  +++ |+#include <vector>
    5 | using namespace std;
main.cpp:34:25: error: expected primary-expression before ‘int’
   34 |   dp.assign(n+1, vector<int>(k+1, -1));
      |                         ^~~
main.cpp:33:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   int n, k; scanf("%d%d", &n, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;
using i64 = long long;

constexpr int mod = int(powl(10, 9)) + 7;
vector<vector<int>> dp;

int f(int n, int k) {
  k = min(k, n*(n-1)/2);
  int &res = dp[n][k];
  if(res != -1) { return res; }
  if(n == 0 && k == 0) { return res = 1; }
  res = 0;
  if(k >= 1) {
    res += f(n, k-1);
    res %= mod;
  }
  res += f(n-1, k);
  res %= mod;
  if(k >= n) {
    res -= f(n-1, k-n);
    res %= mod;
    res += mod;
    res %= mod;
  }
  return res;
}

int main(void) {
  int n, k; scanf("%d%d", &n, &k);
  dp.assign(n+1, vector<int>(k+1, -1));
  int res = f(n, k);
  printf("%d\n", res);
  return 0;
}
0