Submission #94355

# Submission time Handle Problem Language Result Execution time Memory
94355 2019-01-18T01:08:47 Z jasony123123 Uzastopni (COCI15_uzastopni) C++11
64 / 160
49 ms 14456 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <array>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"

typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }

void io() {
#ifdef LOCAL_PROJECT 
	freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else 
	/* online submission */

#endif 
	ios_base::sync_with_stdio(false); cin.tie(NULL);
}

const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const ll INF = 1e18;
/**************************COCI15 R1 P6 uzastopni************************************/
typedef array<bitset<100>, 100> dpt;
const int SZ = 10000;
int N, J[SZ];
v<int> adj[SZ];
array<bitset<100>, 100> dp[SZ];
v<pii> easy[100];

void dfs(int x, int p) {
	if (adj[x].size() == 1) { // leaf
		dpt &curdp = dp[x];
		curdp[J[x]][J[x]] = 1;
	}
	else {
		dpt trans;
		dpt &curdp = dp[x];
		for (auto c : adj[x]) if (c != p) {
			dfs(c, x);
			FOR(i, 0, 100) trans[i] |= dp[c][i];
		}
		RFORE(l, 99, J[x] + 1) {
			curdp[l] = trans[l];
			FORE(r, l, 99) if (trans[l][r] && r + 1 <= 99) {
				curdp[l] |= curdp[r + 1];
			}
		}
		curdp[J[x]][J[x]] = 1;
		if (J[x] != 99)
			curdp[J[x]] |= curdp[J[x] + 1];
		RFORE(l, J[x] - 1, 0) {
			FORE(r, l, J[x] - 1) if (trans[l][r]) {
				curdp[l][r] = 1;
				curdp[l] |= curdp[r + 1];
			}
		}
		FOR(l, 0, 100) FOR(r, l, 100) if (dp[x][l][r] && r < J[x] || J[x] < l)
			dp[x][l][r] = 0;
	}
	FOR(l, 0, 100) FOR(r, l, 100) if (dp[x][l][r])
		easy[x].push_back({ l,r });
}
int main() {
	io();
	cin >> N;
	FOR(i, 0, N) {
		cin >> J[i];
		J[i]--;
	}
	FOR(i, 0, N - 1) {
		int a, b; cin >> a >> b;
		adj[a - 1].push_back(b - 1), adj[b - 1].push_back(a - 1);
	}
	dfs(0, -1);
	int ans = 0;
	FOR(i, 0, 100)
		ans += dp[0][i].count();
	cout << ans << "\n";
}

Compilation message

uzastopni.cpp: In function 'void dfs(int, int)':
uzastopni.cpp:79:49: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   FOR(l, 0, 100) FOR(r, l, 100) if (dp[x][l][r] && r < J[x] || J[x] < l)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 764 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Incorrect 2 ms 632 KB Output isn't correct
7 Incorrect 2 ms 632 KB Output isn't correct
8 Correct 4 ms 888 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Runtime error 49 ms 14456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 30 ms 8824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 32 ms 9288 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Incorrect 6 ms 1016 KB Output isn't correct
15 Incorrect 5 ms 1016 KB Output isn't correct
16 Incorrect 5 ms 1016 KB Output isn't correct
17 Runtime error 45 ms 13900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 33 ms 10748 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 18 ms 5240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 14 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)