# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
933013 | 2024-02-24T19:47:59 Z | ArashJafariyan | Zagrade (COI17_zagrade) | C++17 | 41 ms | 8440 KB |
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "debug.h" #else #define debug(...) 0 #endif typedef long long ll; const int N = 3e5 + 4; int n, _f[2 * N], ans[N]; string s; int& f(int k) { k += N; return _f[k]; } int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 0; i < 2 * N; i++) { _f[i] = N; } cin >> n >> s; for (int i = 1; i < n; i++) { int v, u; cin >> v >> u; } int sum = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == '(') { sum--; f(1 + sum) = i; } else { sum++; f(-1 + sum) = i; } int R = f(sum); if (R < n && s[i] == '(') { ans[i] = ans[R + 1] + 1; } } ll Ans = 0; for (int i = 0; i < n; i++) { Ans += ans[i]; debug(i, ans[i]); } cout << Ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3676 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 8440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 3676 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |