Submission #25901948


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, n) for (int i = 0; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)

int  N;
string S;

bool check() {
  int c = 0;
  REP(n, N) {
    if (S[n] == ')' && c == 0) { return false; }
    if (S[n] == '(') { c++; } else { c--; }
  }
  return c == 0;
}


void loop(int depth) {
  if (depth == N) {
    if (check()) { cout << S << endl; }
    return;
  }

  S[depth] = '(';
  loop(depth + 1);
  S[depth] = ')';
  loop(depth + 1);
}

int main() {
  cin >> N;
  if (N % 2 == 1) { return 0; }

  S = string(N, ' ');

  loop(0);

  return 0;
}

Submission Info

Submission Time
Task 002 - Encyclopedia of Parentheses(★3)
User ryo_ryo66
Language C++ (GCC 9.2.1)
Score 3
Code Size 635 Byte
Status AC
Exec Time 55 ms
Memory 3536 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 3 / 3
Status
AC × 4
AC × 20
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 01_sample_04.txt, 02_all_01.txt, 02_all_02.txt, 02_all_03.txt, 02_all_04.txt, 02_all_05.txt, 02_all_06.txt, 02_all_07.txt, 02_all_08.txt, 02_all_09.txt, 02_all_10.txt, 02_all_11.txt, 02_all_12.txt, 02_all_13.txt, 02_all_14.txt, 02_all_15.txt, 02_all_16.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 9 ms 3440 KiB
01_sample_02.txt AC 2 ms 3472 KiB
01_sample_03.txt AC 2 ms 3324 KiB
01_sample_04.txt AC 2 ms 3392 KiB
02_all_01.txt AC 2 ms 3512 KiB
02_all_02.txt AC 2 ms 3444 KiB
02_all_03.txt AC 2 ms 3536 KiB
02_all_04.txt AC 2 ms 3532 KiB
02_all_05.txt AC 2 ms 3532 KiB
02_all_06.txt AC 2 ms 3504 KiB
02_all_07.txt AC 2 ms 3516 KiB
02_all_08.txt AC 2 ms 3432 KiB
02_all_09.txt AC 2 ms 3528 KiB
02_all_10.txt AC 5 ms 3452 KiB
02_all_11.txt AC 2 ms 3316 KiB
02_all_12.txt AC 11 ms 3516 KiB
02_all_13.txt AC 2 ms 3316 KiB
02_all_14.txt AC 23 ms 3472 KiB
02_all_15.txt AC 2 ms 3424 KiB
02_all_16.txt AC 55 ms 3528 KiB