| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 210174 | ZwariowanyMarcin | Uzastopni (COCI15_uzastopni) | C++14 | 38 ms | 11512 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 1e4 + 10;
const int K = 110;
const int V = 100;
int n;
int a, b;
vector <int> v[N];
int prawo[N][K], lewo[N][K];
int c[N];
void dfs(int u) {
	vector <int> L, R;
	for (auto it : v[u]) {
		dfs(it);
		if (c[it] < c[u]) L.pb(it);
		if (c[it] > c[u]) R.pb(it);
	}
	prawo[u][c[u]] = 1;
	lewo[u][c[u]] = 1;
	sort(R.begin(), R.end(), [](int a, int b) {
		return c[a] < c[b];
	});
	sort(L.begin(), L.end(), [](int a, int b) {
		return c[a] > c[b];
	});
	for (auto it : R)
		rep(Left, c[u] + 1, V)
			rep(Right, Left, V)
				prawo[u][Right] |= (lewo[it][Left] & prawo[it][Right] & prawo[u][Left - 1]);
	
	for (auto it : L)
		rep(Left, 1, c[u] - 1)
			rep(Right, Left, c[u] - 1)
				lewo[u][Left] |= (lewo[it][Left] && prawo[it][Right] & lewo[u][Right + 1]);
}
int main() {
	scanf ("%d", &n);
	rep(i, 1, n) scanf ("%d", c + i);
	rep(i, 1, n - 1) {
		scanf ("%d%d", &a, &b);
		v[a].pb(b);
	}
	dfs(1);
	int L = 0;
	int R = 0;
	rep(i, 1, V) {
		L += lewo[1][i];
		R += prawo[1][i];
	}
	printf ("%d\n", L * R);
		
	return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
