QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21297. Bò vụng về

Statistics

Bessie cố gõ chuỗi ngoặc cân bằng trên máy tính xách tay mới, nhưng móng lớn khiến cô vụng về và gõ sai. Tìm số ký tự ít nhất phải đảo (ngoặc mở thành đóng hoặc ngược lại) để chuỗi cân bằng.

Có nhiều định nghĩa cân bằng. Đơn giản nhất là tổng số ngoặc mở và đóng bằng nhau, và trong mọi tiền tố số ngoặc mở không ít hơn số ngoặc đóng. Các chuỗi sau cân bằng:

()
(())
()(()())

Các chuỗi này không cân bằng:

)(
())(
((())))

Dữ liệu vào

  • Dòng 1: chuỗi ngoặc $A$ có độ dài chẵn, tối đa 100,000 ký tự.

Dữ liệu ra

  • Dòng 1: số nguyên, số ngoặc ít nhất cần đảo để chuỗi cân bằng.

Ví dụ

Dữ liệu vào 1

())(

Dữ liệu ra 1

2

Ghi chú

Phải đảo ngoặc cuối và một trong hai ngoặc đóng ở giữa.

Tác giả: Brian Dean, 2012

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.