QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#260149 | #1194. Parehtneses Editor | lemonilemon# | WA | 2ms | 3808kb | C++20 | 1.6kb | 2023-11-21 21:04:57 | 2023-11-21 21:04:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef genshin
#include <experimental/iterator>
#endif
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using uint = unsigned int;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 46 * ll(1e17);
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 25;
struct good{
map<int,int> cnt;
vector<pair<int, char>> rec;
pair<int, char> last(){
if (rec.empty()) return make_pair(-2, '*');
else return rec.back();
}
};
vector <good> rec;
signed main() { ios::sync_with_stdio(0); cin.tie(0);
char c;
ll ans = 0;
rec.push_back(good());
while (cin >> c){
if (c == '('){
int i = rec.back().last().first + 1;
if (i <= 0){
rec.push_back(good());
i = 1;
}
++rec.back().cnt[i-1];
rec.back().rec.push_back(make_pair(i, c));
}
else if (c == ')'){
int i = rec.back().last().first - 1;
if (i >= 0){
ans += rec.back().cnt[i];
}
rec.back().rec.push_back(make_pair(i, c));
}
else{
if (rec.back().last().second == '('){
int i = rec.back().last().first;
--rec.back().cnt[i-1];
}
else{
int i = rec.back().last().first;
if (i >= 0){
ans -= rec.back().cnt[i];
}
}
rec.back().rec.pop_back();
if (rec.back().last().first == -2) rec.pop_back();
}
cout << ans << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
(()())---)
output:
0 0 1 1 3 4 3 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
()--()()----)(()()))
output:
0 1 0 0 0 1 1 3 1 1 0 0 0 0 0 1 1 3 4 4
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3808kb
input:
))(((-)(()((---(-)(-())-(()()(-)--(())))--()((())-)(()(())((-))))(-(((()((()()()()))-(())((((--))-())-)(-(--))))((((-)(-(-)((((()--(---)(-))()(-)(()()-(())()(()()((()()))))(()(()(-(--)-()((()(((()-))-)(()-()()-(-((-)(-)(((()-)))))-())()-(()((()(-)()))((-))())))()()()(-(-(())-()(()-)-))((()))((--(-()...
output:
0 0 0 0 0 0 1 1 1 2 2 2 2 2 1 1 1 2 2 2 2 4 6 4 4 4 5 5 7 7 7 10 7 5 5 5 6 7 9 12 9 7 7 9 9 9 9 10 12 10 12 12 12 14 14 14 15 18 18 18 18 22 25 28 30 30 30 30 30 30 30 35 35 35 35 36 36 38 38 41 41 45 47 53 47 47 47 52 55 55 55 55 55 55 55 61 65 61 61 68 72 68 72 72 72 72 72 68 72 78 82 86 86 86 86 ...
result:
wrong answer 49th numbers differ - expected: '11', found: '12'