# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154153 | 2019-09-18T16:16:02 Z | Ruxandra985 | Uzastopni (COCI15_uzastopni) | C++14 | 500 ms | 9080 KB |
#include <cstdio> #include <iostream> #include <vector> #include <bitset> using namespace std; bitset <10001> dp[101][101]; vector <int> v[10001]; int joke[10001],k; void dfs (int nod){ int i,vecin,x,y,z,len; dp[joke[nod]][joke[nod]][nod] = 1; for (i=0;i<v[nod].size();i++){ dfs (v[nod][i]); vecin = v[nod][i]; /// acum e acum:P if (joke[vecin]!=joke[nod]) dp[joke[vecin]][joke[vecin]][nod] = 1; for (x = 1; x <= k ;x ++) for (y = x ;y <= k ; y++){ if (x > joke[nod] || y < joke[nod]) dp[x][y][nod] = (dp[x][y][nod] | dp[x][y][vecin]); } } for (len = 2; len <= k ;len++){ for (x = 1; x + len - 1 <= k ; x++){ y = x + len - 1; for (z=x;z<y && !dp[x][y][nod];z++){ dp[x][y][nod] = (dp[x][z][nod] & dp[z+1][y][nod]); } } } for (x=1;x<=k;x++){ for (y=x;y<=k;y++){ if (x > joke[nod] || y < joke[nod]) dp[x][y][nod] = 0; } } } int main() { FILE *fin = stdin; FILE *fout = stdout; int n,i,x,y,sol,j; fscanf (fin,"%d",&n); for (i=1;i<=n;i++){ fscanf (fin,"%d",&joke[i]); k = max ( k ,joke[i]); } for (i=1;i<n;i++){ fscanf (fin,"%d%d",&x,&y); v[x].push_back(y); } dfs (1); sol = 0; for (i=1;i<=joke[1];i++) for (j=joke[1];j<=k;j++){ sol = sol + dp[i][j][1]; } fprintf (fout,"%d",sol); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 760 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
3 | Correct | 3 ms | 632 KB | Output is correct |
4 | Correct | 3 ms | 632 KB | Output is correct |
5 | Correct | 3 ms | 632 KB | Output is correct |
6 | Correct | 64 ms | 7032 KB | Output is correct |
7 | Correct | 63 ms | 7032 KB | Output is correct |
8 | Correct | 65 ms | 7032 KB | Output is correct |
9 | Correct | 61 ms | 6904 KB | Output is correct |
10 | Correct | 59 ms | 6904 KB | Output is correct |
11 | Correct | 27 ms | 1244 KB | Output is correct |
12 | Correct | 15 ms | 1016 KB | Output is correct |
13 | Correct | 9 ms | 888 KB | Output is correct |
14 | Execution timed out | 1070 ms | 9032 KB | Time limit exceeded |
15 | Execution timed out | 1088 ms | 9080 KB | Time limit exceeded |
16 | Execution timed out | 1074 ms | 9080 KB | Time limit exceeded |
17 | Correct | 9 ms | 888 KB | Output is correct |
18 | Correct | 9 ms | 888 KB | Output is correct |
19 | Execution timed out | 1074 ms | 7596 KB | Time limit exceeded |
20 | Execution timed out | 1054 ms | 7376 KB | Time limit exceeded |