/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Accepted 4ms 532.0 KiB
#3 Wrong Answer 4ms 320.0 KiB

Code

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

int n;

void generate(string curr, vector<int>& open, int pairs1, int pairs2) {
    if(curr.length() == n) {
        cout << curr << '\n';
        return;
    }
    
    // Track open brackets for each type
    int open1 = open[0], open2 = open[1];
    
    // Try adding '(' if we haven't used all pairs
    if(pairs1 > 0) {
        open[0]++;
        generate(curr + '(', open, pairs1-1, pairs2);
        open[0]--;
    }
    
    // Try adding ')' if we have unclosed '('
    if(open1 > 0) {
        open[0]--;
        generate(curr + ')', open, pairs1, pairs2);
        open[0]++;
    }
    
    // Try adding '[' if we haven't used all pairs
    if(pairs2 > 0) {
        open[1]++;
        generate(curr + '[', open, pairs1, pairs2);
        open[1]--;
    }
    
    // Try adding ']' if we have unclosed '['
    if(open2 > 0) {
        open[1]--;
        generate(curr + ']', open, pairs1, pairs2);
        open[1]++;
    }
}

int main() {
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    cin >> n;
    if(n & 1) return 0;  // Odd length not possible
    
    vector<int> open(2, 0);  // Track open ( and [ separately
    generate("", open, n/2, n/2);
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1170 Regular bracket sequence
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-22 20:00:50
Judged At
2025-02-22 20:00:50
Judged By
Score
5
Total Time
4ms
Peak Memory
532.0 KiB