답안 #931645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931645 2024-02-22T07:45:31 Z vjudge1 Zagrade (COI17_zagrade) C++17
0 / 100
18 ms 1520 KB
// 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

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){
      |                  ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 1520 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -