QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214819#5108. Prehistoric ProgramsYYYYYYYYRE 0ms0kbC++14943b2023-10-15 00:16:282023-10-15 00:16:29

Judging History

你现在查看的是最新测评结果

  • [2023-10-15 00:16:29]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-15 00:16:28]
  • 提交

answer

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int num;
	cin >> num;
	vector<vector<int>> v(num);
	for(int i = 0; i < num; i++){
		v[i][2] = i + 1;
		string s;
		cin >> s;
		int mn = 0, cur = 0;
		for(auto x : s){
			if(x == '(')cur++;
			else cur--;
			mn = min(mn, cur);
		}
		cur -= mn;
		v[i][0] = cur;
		v[i][1] = -mn;
	}
	
	sort(v.begin(), v.end(), [&](const vector<int> &a, const vector<int> &b){
    int s1 = (a[0] == a[1] ? 0 : (a[0] > a[1] ? 1 : -1));
    int s2 = (b[0] == b[1] ? 0 : (b[0] > b[1] ? 1 : -1));
    if (s1 != s2) return s1 > s2;
    if (s1 == 1) return a[1] < b[1];
    else return a[0] > b[0];
});
	
	int mn = 0, cur = 0;
	for(auto x : v){
		mn = min(mn, cur - x[1]);
		cur += x[0] - x[1];
	}
	
	if(mn < 0 || cur != 0)cout << "impossible\n";
	else {
		for(auto x : v){
			cout << x[2] << "\n";
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

50000
(
(
))))()))()(()))()()()))()(((((()(((()))()(((()))((()(())))))(()(
)
(
)
(((
(
(
(
(
(
()
(
)
(
)((())()((
)))))(
(
)
))
)()
(
)
)
)()(
(
(
()
(
)
(
)()((((())()))())(
(
(
)(
(
(
(()())())
)
)
(
(
(
)((())))((())))))))))((((()()))()))))))))((()())()))
)
)()
)
)
)
)
)
())(())))))()(()((()(())...

output:


result: