Submission #931645

#TimeUsernameProblemLanguageResultExecution timeMemory
931645vjudge1Zagrade (COI17_zagrade)C++17
0 / 100
18 ms1520 KiB
// in the name of God #include<bits/stdc++.h> using namespace std; #define int long long #define fast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define pb(x) push_back(x) #define all(x) x.begin(), x.end() #define mk make_pair #define ppb pop_back #define endl '\n' #define pii pair<int, int> #define sz(x) (int)x.size() #define file() freopen("input.txt", "r", stdin); #pragma GCC optimize("Ofast") #pragma GCC optimize("O4") #pragma GCC optimize("unroll-loops") //#pragma GCC target("avx2") mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 1e9 + 7, maxn = 2e3 + 10, sq = 3163, inf = 1e18 + 10, lg = 25, pp = 4447, modd = 1e9 + 9; int n, ans; string s; vector<vector<int>> g(maxn); void dfs(int u, int par = -1, string ss = ""){ ss += s[u]; if(ss.size() % 2 == 0){ int x = 0, y = 0; for(int i = 0; i < ss.size(); ++i){ if(ss[i] == '(') x++; else y++; if(y > x) return; } ans++; } for(int v : g[u]){ if(v != par) dfs(v, u, ss); } } signed main(){ fast();//file(); cin >> n >> s; for(int i = 1; i < n; ++i){ int u, v; cin >> u >> v; u--; v--; g[v].pb(u); g[u].pb(v); } for(int i = 0; i < n; ++i){ dfs(i); } cout << ans / 2; } // Running from the daylight...

Compilation message (stderr)

zagrade.cpp: In function 'void dfs(long long int, long long int, std::string)':
zagrade.cpp:30:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i = 0; i < ss.size(); ++i){
      |                  ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...