QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#217794 | #5108. Prehistoric Programs | ling__fang_ | WA | 932ms | 3936kb | C++14 | 1.6kb | 2023-10-17 13:17:06 | 2023-10-17 13:17:07 |
Judging History
answer
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class parenthesis
{
public:
int left = 0, right = 0;
};
int main()
{
int n;
cin >> n;
vector<parenthesis> p(n);
vector<int> answer(n);
int start = -1, end = 0, balance = 0;
for (int i = 0; i < n; i++)
{
string paren;
cin >> paren;
for (int j = 0; j < paren.length(); j++)
{
if (paren[j] == '(')
{
balance++;
p[i].left++;
}
else if (paren[j] == ')' && p[i].left > 0)
{
balance--;
p[i].left--;
}
else if (paren[j] == ')' && p[i].left == 0)
{
balance--;
p[i].right++;
}
}
if (p[i].left == 0 && p[i].right != 0)
end = 1;
if (p[i].right == 0 && p[i].left != 0 && (start == -1 || p[i].left > p[start].left))
start = i;
}
if (balance != 0 || start == -1 || end == 0)
{
balance = 1;
}
else
{
int quota = p[start].left;
answer[0] = start;
p[start].right = -1;
int next = -1;
for (int j = 1; j < n; j++)
{
for (int i = 0; i < n; i++)
{
if (p[i].right <= quota && p[i].right != -1 && (next == -1 || p[i].right < p[next].right))
{
next = i;
}
}
if (next == -1)
{
balance = 1;
break;
}
quota = quota - p[next].left + p[next].right;
answer[j] = next;
}
}
if (balance != 0)
{
cout << "impossible";
}
else
{
for (int i = 0; i < n; i++)
cout << answer[i] + 1 << endl;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 932ms
memory: 3936kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
41248 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer your output is not a permutation of 1...n