QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217789#5108. Prehistoric Programsling__fang_WA 24ms5896kbC++14797b2023-10-17 13:00:332023-10-17 13:00:34

Judging History

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

  • [2023-10-17 13:00:34]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:5896kb
  • [2023-10-17 13:00:33]
  • 提交

answer

#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<string> tablets(n);
  vector<pair<int, int>> balance(n);

  for(int i = 0; i < n; i++)
  {
    cin >> tablets[i];
    int balance_cnt = 0;
    for (char c : tablets[i])
      if(c == '(')
        balance_cnt++;
      else
        balance_cnt--;

    balance[i] = {balance_cnt, i + 1};
  }

  sort(balance.begin(), balance.end());
  

  // check the balance first
  int balance_sum = 0;
  for(int i = 0; i < n; i++)
    balance_sum += balance[i].first;
  
  if(balance_sum != 0)
  {
    cout << "impossible";
    return 0;
  }

  for(int i = n - 1; i >= 0; i--)
  {
    cout << balance[i].second << endl;
  }
}

详细

Test #1:

score: 100
Accepted
time: 24ms
memory: 5896kb

input:

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

output:

6827
17933
39338
30523
11635
8378
1194
39997
15203
12662
8282
34305
41357
24534
33154
37628
20200
45720
29189
40093
27739
38177
35948
32454
41248
28930
42456
48879
12655
12299
46182
21094
4238
49233
44459
35822
33371
21519
18388
13809
9449
37172
27579
3502
48479
39917
15706
4704
40407
30710
47826
41...

result:

ok good plan

Test #2:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

1000
(
))(()))
((((())())))((())(()))(
)(
)
)))
))((()(((((((())()(())()())))(()(())()())))))))((()((()())()())(())))()((()())
)((()()()(())(()))()(())()))(()))))())))))))))))))()))(()()(())(()))())()()))))(())()()()((())(()))(())))))))(()()())()))()())))()()))))))(
)))(((
(
)))()()())))
(
(((())(((...

output:

36
980
537
519
480
472
634
13
745
194
994
66
386
896
186
776
44
354
966
904
532
645
946
585
167
571
488
132
694
38
587
286
264
159
257
218
141
127
83
448
417
39
595
478
476
907
814
720
598
543
507
329
214
107
981
427
111
62
956
780
707
700
662
384
362
349
300
260
131
996
845
807
793
705
676
600
581
...

result:

ok good plan

Test #3:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

2
()
()

output:

2
1

result:

ok good plan

Test #4:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

2
((
))

output:

1
2

result:

ok good plan

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3752kb

input:

2
)(
()

output:

2
1

result:

wrong answer wrong plan (expected impossible)