Submission #144897

#TimeUsernameProblemLanguageResultExecution timeMemory
144897emilemZagrade (COI17_zagrade)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <string> #include <vector> using namespace std; long long ans; int n; int op, clos; string path; vector< vector<int> > nei; string a; void Chain(const string& a) { vector<int> pref(a.length()); for (int i = 0; i < pref.size(); ++i) { if (a[i] == '(') ++pref[i]; else --pref[i]; if (i) pref[i] += pref[i - 1]; } } void Dfs(int v, int par) { if (op == clos && a[v] == ')') return; if (a[v] == ')') ++clos; else ++op; path += a[v]; if (clos == op) ++ans; for (int i = 0; i < nei[v].size(); ++i) { int to = nei[v][i]; if (to == par) continue; Dfs(to, v); } path.pop_back(); if (a[v] == ')') --clos; else --op; } int main() { cin >> n; nei.resize(n); cin >> a; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; --u; --v; nei[u].push_back(v); nei[v].push_back(u); } if (n <= 1000) { for (int v = 0; v < n; ++v) { op = clos = 0; path = ""; Dfs(v, -1); } cout << ans << endl; return 0; } else // Is a chain. { ans += Chain(a); reverse(a.begin(), a.end()); ans += Chain(a); cout << ans << endl; char I; cin >> I; return 0; vector<int> st(n, -1), dp(n); for (int i = 0; i < n; ++i) { if (op == clos && a[i] == ')') { op = clos = 0; path = ""; continue; } if (a[1] == ')') ++clos; else ++op; path += a[i]; if (op == clos) { st[i] = i - (int)path.length() + 1; op = clos = 0; path = ""; } } long long cnt = 0; for (int i = n - 1; i >= 0; ) { if (st[i] == -1) { ans += (cnt * (cnt - 1)) / 2; cnt = 0; --i; } else { ++cnt; i = st[i] - 1; if (i < 0) ans += (cnt * (cnt - 1)) / 2; } } cout << ans << endl; } char I; cin >> I; }

Compilation message (stderr)

zagrade.cpp: In function 'void Chain(const string&)':
zagrade.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < pref.size(); ++i)
                  ~~^~~~~~~~~~~~~
zagrade.cpp: In function 'void Dfs(int, int)':
zagrade.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < nei[v].size(); ++i)
                  ~~^~~~~~~~~~~~~~~
zagrade.cpp: In function 'int main()':
zagrade.cpp:67:7: error: invalid operands of types 'long long int' and 'void' to binary 'operator+'
   ans += Chain(a);
   ~~~~^~~~~~~~~~~
zagrade.cpp:67:17: error:   in evaluation of 'operator+=(long long int, void)'
   ans += Chain(a);
                 ^
zagrade.cpp:68:3: error: 'reverse' was not declared in this scope
   reverse(a.begin(), a.end());
   ^~~~~~~
zagrade.cpp:69:7: error: invalid operands of types 'long long int' and 'void' to binary 'operator+'
   ans += Chain(a);
   ~~~~^~~~~~~~~~~
zagrade.cpp:69:17: error:   in evaluation of 'operator+=(long long int, void)'
   ans += Chain(a);
                 ^