Submission #933013

#TimeUsernameProblemLanguageResultExecution timeMemory
933013ArashJafariyanZagrade (COI17_zagrade)C++17
0 / 100
41 ms8440 KiB
#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 (stderr)

zagrade.cpp: In function 'int main()':
zagrade.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 0
      |                    ^
zagrade.cpp:56:9: note: in expansion of macro 'debug'
   56 |         debug(i, ans[i]);
      |         ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...