結果

問題 No.790 ちきんの括弧並べ
ユーザー hiro1729hiro1729
提出日時 2023-07-21 15:48:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 86,616 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:25:23
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 12 ms
4,348 KB
testcase_09 AC 36 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int n;
int k = 0;

int string_sum(string s) {
  int ans = 0;
  for (char c: s) ans += c - '0';
  return ans;
}

void rec(int x, string s) {
  if (x == n - 1) {
    k++;
    return;
  }
  for (int i = 0; i < x + 2 - string_sum(s); i++)
    rec(x + 1, s + char(48 + i));
}

int main() {
  cin >> n;
  rec(0, "");
  cout << k << '\n';
}
0