結果

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

コンパイルメッセージ
main.cpp:8:25: error: ‘powl’ was not declared in this scope
 constexpr int mod = int(powl(10, 9)) + 7;
                         ^~~~
main.cpp:8:25: note: suggested alternative: ‘bool’
 constexpr int mod = int(powl(10, 9)) + 7;
                         ^~~~
                         bool
main.cpp:9:1: error: ‘vector’ does not name a type; did you mean ‘perror’?
 vector<vector<int>> dp;
 ^~~~~~
 perror
main.cpp: In function ‘int f(int, int)’:
main.cpp:13:14: error: ‘dp’ was not declared in this scope
   int &res = dp[n][k];
              ^~
main.cpp: In function ‘int main()’:
main.cpp:34:3: error: ‘dp’ was not declared in this scope
   dp.assign(n+1, vector<int>(k+1, -1));
   ^~
main.cpp:34:18: error: ‘vector’ was not declared in this scope
   dp.assign(n+1, vector<int>(k+1, -1));
                  ^~~~~~
main.cpp:34:18: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:5:1:
+#include <vector>
 using namespace std;
main.cpp:34:18:
   dp.assign(n+1, vector<int>(k+1, -1));
                  ^~~~~~
main.cpp:34:25: error: expected primary-expression before ‘int’
   dp.assign(n+1, vector<int>(k+1, -1));
                         ^~~

ソースコード

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