QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#356446 | #5108. Prehistoric Programs | TWTP_TCTF# | WA | 7ms | 4136kb | C++14 | 1.6kb | 2024-03-17 19:48:14 | 2024-03-17 19:48:14 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 1e4 + 9, MOD = 998244353;
// + +, - - , - +
//((( , ))) , )))(((
pair<int, int> calc(string &s) {
int cnt = 0;
int mn = 0;
for (auto i: s) {
if (i == '(') {
cnt++;
} else {
cnt--;
}
mn = min(mn, cnt);
}
return {mn, cnt};
}
// )))) , )))(((( -3 , 1 // )((( ))))))) ((((((((((( // 7,5 // 5,5
bool sortt(pair<int, pair<int, int> > &x, pair<int, pair<int, int> > &y) {
pair<int, int> a = x.second, b = y.second;
if (a.second >= 0 && b.second >= 0) {
return a.first > b.first;
}
if (a.second <= 0 && b.second <= 0) {
return a.first < b.first;
}
return a.second > b.second;
}
void doWork() {
// x , d
int n;
cin >> n;
vector<pair<int, pair<int, int> > > v;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
v.push_back({i, calc(s)});
}
sort(v.begin(), v.end(), sortt);
ll total = 0;
for (auto i: v) {
if (total + i.second.first < 0) {
cout << "impossible";
return;
}
total += i.second.second;
}
if (total != 0) {
cout << "impossible";
} else {
for (auto i: v)cout << i.first << "\n";
}
}
int main() {
IO
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << ": ";
doWork();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 4136kb
input:
50000 ( ( ))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()( ) ( ) ((( ( ( ( ( ( () ( ) ( )((())()(( )))))( ( ) )) )() ( ) ) )()( ( ( () ( ) ( )()((((())()))())( ( ( )( ( ( (()())()) ) ) ( ( ( )((())))((())))))))))((((()()))()))))))))((()())())) ) )() ) ) ) ) ) ())(())))))()(()((()(())...
output:
impossible
result:
wrong answer you didn't find a solution but jury did