QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583089 | #5108. Prehistoric Programs | deepthought | WA | 7ms | 7232kb | C++23 | 1.4kb | 2024-09-22 18:17:19 | 2024-09-22 18:17:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
pair<int, int> look(const string& s) {
int fin = 0;
int minima = 0;
for(int i = 0; i < s.length(); i++) {
if(s[i] == '(') fin++;
else fin--;
// if(s.length() == 150) cout << i << " " << fin << endl;
minima = min(fin, minima);
}
return {fin, minima};
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <string> a(n + 1);
vector <pair <int, int>> v1;
vector <pair <int, int>> v2;
for(int i = 1; i <= n; i++) {
cin >> a[i];
auto ax = look(a[i]);
int minima = ax.second;
int fin = ax.first;
if(fin >= 0) {
v1.push_back({-minima, i});
}
else {
v2.push_back({-fin, i});
}
}
vector <int> ans;
string s = "";
sort(v1.begin(), v1.end());
for(auto x: v1) {
int idx = x.second;
s += a[idx];
ans.push_back(idx);
}
sort(v2.begin(), v2.end());
for(auto x: v2) {
int idx = x.second;
s += a[idx];
// cout << idx << " " << a[idx] << endl;
ans.push_back(idx);
}
auto bx = look(s);
if(bx.second >= 0 && bx.first == 0) {
for(auto x: ans)
cout << x << '\n';
}
else cout << "impossible" << '\n';
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 7232kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did