답안 #1057039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057039 2024-08-13T13:31:06 Z pan Uzastopni (COCI15_uzastopni) C++17
160 / 160
28 ms 29780 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i) 
#define RFOR(i, x, n) for (ll i =x; i>=n; --i) 
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> piii;

ll const MAXN = 10000, MAXV = 100;
ll n, v, e;
vector<ll> adj[10005];
bitset<105> dp[10005][105];
vector<pi> s[10005];
vector<ll> nxt[105];
ll val[10005];
void dfs(ll x)
{

	for (ll u: adj[x])  dfs(u);
	for (ll i=1; i<=MAXV; ++i) nxt[i].clear();
	for (ll u: adj[x]) for (pi a: s[u]) nxt[a.f].pb(a.s);
	for (ll i = MAXV; i>=1; --i)
	{
		if (i == val[x]) // {val[x]} U other pairs
		{
			dp[x][i] |= dp[x][i+1];
			dp[x][i][i] = 1;
			continue;
		}
		// pair U other pairs
		for (ll u: nxt[i]) 
		{
			//show(u);
			if (u < val[x] || i > val[x])
			{
				dp[x][i] |= dp[x][u+1];
				dp[x][i][u] = 1;
				//cout << dp[x][i] << endl;
			}
		}
	}
	for (ll i = 1; i<=val[x] ; ++i) for (ll j=val[x]; j<=MAXV; ++j) if (dp[x][i][j]) s[x].pb(mp(i, j));
	//show(x);
	//for (pi u: s[x]) show2(u.f, u.s);
}

int main()
{
	input(n);
	for (ll i=1; i<=n; ++i) input(val[i]);
	for (ll i=0; i<n-1; ++i)
	{
		input2(v, e);
		adj[v].pb(e);
	}
	dfs(1);
	ll ans = s[1].size();
	print(ans, '\n');
	return 0;
}

Compilation message

uzastopni.cpp: In function 'int main()':
uzastopni.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
uzastopni.cpp:76:2: note: in expansion of macro 'input'
   76 |  input(n);
      |  ^~~~~
uzastopni.cpp:12:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
uzastopni.cpp:77:26: note: in expansion of macro 'input'
   77 |  for (ll i=1; i<=n; ++i) input(val[i]);
      |                          ^~~~~
uzastopni.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:80:3: note: in expansion of macro 'input2'
   80 |   input2(v, e);
      |   ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 0 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 0 ms 2652 KB Output is correct
11 Correct 15 ms 17756 KB Output is correct
12 Correct 14 ms 17756 KB Output is correct
13 Correct 13 ms 18264 KB Output is correct
14 Correct 28 ms 29740 KB Output is correct
15 Correct 28 ms 29776 KB Output is correct
16 Correct 28 ms 29780 KB Output is correct
17 Correct 14 ms 18012 KB Output is correct
18 Correct 12 ms 18012 KB Output is correct
19 Correct 22 ms 22392 KB Output is correct
20 Correct 22 ms 22356 KB Output is correct