結果

問題 No.616 へんなソート
コンテスト
ユーザー siman
提出日時 2023-06-23 23:00:58
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 832 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,284 ms
コンパイル使用メモリ 146,560 KB
実行使用メモリ 56,684 KB
最終ジャッジ日時 2026-03-21 19:46:14
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   int A[N];
      |         ^
main.cpp:21:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N, K;
      |       ^
main.cpp:26:17: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   26 |   int dp[N + 1][K + N + 1];
      |                 ^~~~~~~~~
main.cpp:26:17: note: read of non-const variable 'K' is not allowed in a constant expression
main.cpp:19:10: note: declared here
   19 |   int N, K;
      |          ^
main.cpp:26:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   26 |   int dp[N + 1][K + N + 1];
      |          ^~~~~
main.cpp:26:10: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N, K;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int dp[N + 1][K + N + 1];
  memset(dp, 0, sizeof(dp));
  for (int k = 0; k <= K; ++k) {
    dp[0][k] = 1;
  }

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= K; ++j) {
      if (j - i - 1 >= 0) {
        dp[i + 1][j] += dp[i][j] - dp[i][j - i - 1];
      } else {
        dp[i + 1][j] += dp[i][j];
      }
      if (j != 0) dp[i + 1][j] += dp[i + 1][j - 1];

      dp[i + 1][j] %= MOD;
    }
  }

  cout << dp[N][K] << endl;

  return 0;
}
0