QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#225921 | #5108. Prehistoric Programs | b05704085 | TL | 0ms | 0kb | C++23 | 1.3kb | 2023-10-25 11:47:42 | 2023-10-25 11:47:42 |
answer
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <string>
using namespace std;
bool isProperlyNested(const vector<int> &permutation, const vector<string> &tablets)
{
stack<char> s;
for (int num : permutation)
{
const string &tablet = tablets[num - 1];
for (char c : tablet)
{
if (c == '(')
{
s.push(c);
}
else if (c == ')')
{
if (s.empty() || s.top() != '(')
{
return false;
}
s.pop();
}
}
}
return s.empty();
}
int main()
{
int n;
cin >> n;
vector<string> tablets(n);
for (int i = 0; i < n; ++i)
{
cin >> tablets[i];
}
vector<int> originalPermutation(n);
for (int i = 0; i < n; ++i)
{
originalPermutation[i] = i + 1;
}
do
{
if (isProperlyNested(originalPermutation, tablets))
{
for (int num : originalPermutation)
{
cout << num << endl;
}
return 0;
}
} while (next_permutation(originalPermutation.begin(), originalPermutation.end()));
cout << "impossible" << endl;
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...