Submission #1277192

#TimeUsernameProblemLanguageResultExecution timeMemory
1277192vuquangsangUzastopni (COCI15_uzastopni)C++20
80 / 160
66 ms131072 KiB
#include <bits/stdc++.h> using namespace std; const int N = 105; const int MAX = 105; int n, a[N]; vector<int> adj[N]; bool dp[N][MAX][MAX], temp[MAX][MAX]; int lim; void dfs(int u) { for(int v : adj[u]) { dfs(v); } memset(temp, 0, sizeof temp); temp[a[u]][a[u]] = 1; for(int v : adj[u]) { for(int x = 1; x <= lim; x++) { for(int y = x; y <= lim; y++) temp[x][y] |= dp[v][x][y]; } } for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) if(temp[x][y]){ for(int len = y + 1; len <= lim; len++) temp[x][len] |= temp[y + 1][len]; } dp[u][a[u]][a[u]] = 1; for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) { if(x == a[u] && temp[x + 1][y]) dp[u][x][y] = 1; else if(y == a[u] && temp[x][y - 1]) dp[u][x][y] = 1; else if(temp[x][a[u] - 1] && temp[a[u] + 1][y]) dp[u][x][y] = 1; } } void solve() { cin >> n; lim = 100; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); } dfs(1); // #define el "\n" // for(int u = 1; u <= n; u++) { // for(int x = 1; x <= lim; x++) for(int y = 1; y <= lim; y++) cout << u << " " << x << " " << y << " " << dp[u][x][y] << el; cout << el << el; // } int ans = 0; for(int x = 1; x <= lim; x++) for(int y = x; y <= lim; y++) if(dp[1][x][y]) ans++; cout << ans; } main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define TASK "COCI15_uzastopni" if(fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } solve(); cerr << "\nTime" << 0.001 * clock() << "s "; return 0; }

Compilation message (stderr)

uzastopni.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main()
      | ^~~~
uzastopni.cpp: In function 'int main()':
uzastopni.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
uzastopni.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...