Submission #144976

#TimeUsernameProblemLanguageResultExecution timeMemory
144976emilemZagrade (COI17_zagrade)C++14
Compilation error
0 ms0 KiB
#include <algorithm> #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]; } vector<int> r(n, -1); for (int i = 0; i < n; ++i) { int minElem = pref[i]; for (int j = i; j < n; ++j) { minElem = min(minElem, pref[j]); if (minElem - (i ? pref[i - 1] : 0) < 0) break; else r = j; } } for (int i = 0; i <n; ++i) if (r[i] != -1) for (int j = i; j <= r; ++j) if (pref[j] == (i ? pref[i - 1] : 0)) ++ans; } 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 (false/*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. { Chain(a); reverse(a.begin(), a.end()); Chain(a); cout << ans << endl; char I; cin >> I; } char I; cin >> I; }

Compilation message (stderr)

zagrade.cpp: In function 'void Chain(const string&)':
zagrade.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < pref.size(); ++i)
                  ~~^~~~~~~~~~~~~
zagrade.cpp:33:9: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'int')
     r = j;
         ^
In file included from /usr/include/c++/7/vector:69:0,
                 from zagrade.cpp:4:
/usr/include/c++/7/bits/vector.tcc:179:5: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]
     vector<_Tp, _Alloc>::
     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/vector.tcc:179:5: note:   no known conversion for argument 1 from 'int' to 'const std::vector<int>&'
In file included from /usr/include/c++/7/vector:64:0,
                 from zagrade.cpp:4:
/usr/include/c++/7/bits/stl_vector.h:461:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:461:7: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
/usr/include/c++/7/bits/stl_vector.h:482:7: note: candidate: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]
       operator=(initializer_list<value_type> __l)
       ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:482:7: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<int>'
zagrade.cpp:38:22: error: no match for 'operator<=' (operand types are 'int' and 'std::vector<int>')
    for (int j = i; j <= r; ++j)
                    ~~^~~~
In file included from /usr/include/c++/7/utility:70:0,
                 from /usr/include/c++/7/algorithm:60,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:468:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
     operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_pair.h:468:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:323:5: note: candidate: template<class _Iterator> bool std::operator<=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
     operator<=(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:323:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:361:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
     operator<=(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:361:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:1154:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)
     operator<=(const move_iterator<_IteratorL>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1154:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:1160:5: note: candidate: template<class _Iterator> bool std::operator<=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)
     operator<=(const move_iterator<_Iterator>& __x,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:1160:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/string:52:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from zagrade.cpp:2:
/usr/include/c++/7/bits/basic_string.h:6158:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6158:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/string:52:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from zagrade.cpp:2:
/usr/include/c++/7/bits/basic_string.h:6171:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<=(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
     operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6171:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/string:52:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from zagrade.cpp:2:
/usr/include/c++/7/bits/basic_string.h:6183:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<=(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     operator<=(const _CharT* __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/basic_string.h:6183:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const _CharT*' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/vector:64:0,
                 from zagrade.cpp:4:
/usr/include/c++/7/bits/stl_vector.h:1632:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<=(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
     operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
     ^~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:1632:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const std::vector<_Tp, _Alloc>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:923:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator<=(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:923:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
In file included from /usr/include/c++/7/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/7/algorithm:61,
                 from zagrade.cpp:1:
/usr/include/c++/7/bits/stl_iterator.h:916:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<=(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^~~~~~~~
/usr/include/c++/7/bits/stl_iterator.h:916:5: note:   template argument deduction/substitution failed:
zagrade.cpp:38:25: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'int'
    for (int j = i; j <= r; ++j)
                         ^
zagrade.cpp: In function 'void Dfs(int, int)':
zagrade.cpp:51:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < nei[v].size(); ++i)
                  ~~^~~~~~~~~~~~~~~