Submission #717774

# Submission time Handle Problem Language Result Execution time Memory
717774 2023-04-02T13:47:58 Z TheSahib Tropical Garden (IOI11_garden) C++17
49 / 100
5000 ms 6228 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>

using namespace std;

bool comp(pii a, pii b){
    return a.second > b.second;
}

const int MAX = 2e5 + 5;

vector<pii> g[MAX];
int last[MAX];
int t = 1;

int f = 0;
bool dfs(int node, int left){
    if(left == 0){
        return node == f;
    }

    if(g[node].size() == 1 || (last[g[node][0].second] <= last[g[node][1].second])){
        for(pii &a:g[g[node][0].first]){
            last[a.second] = 0;
        }
        last[g[node][0].second] = ++t;
        return dfs(g[node][0].first, left - 1);
    }
    else{
        for(pii &a:g[g[node][1].first]){
            last[a.second] = 0;
        }
        last[g[node][1].second] = ++t;
        return dfs(g[node][1].first, left - 1);
    }
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    f = P;
    for (int i = 0; i < M; i++)
    {
        g[R[i][0]].push_back({R[i][1], M - i - 1});
        g[R[i][1]].push_back({R[i][0], M - i - 1});
    }
    for (int i = 0; i < N; i++)
    {
        sort(g[i].begin(), g[i].end(), comp);
    }
    
    for (int j = 0; j < Q; j++)
    {
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            t = 0;
            fill(last, last + M, 0);
            ans += dfs(i, G[j]);
        }
        answer(ans);
    }
    
}


# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 5 ms 5076 KB Output is correct
3 Correct 5 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 7 ms 5076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 7 ms 5076 KB Output is correct
9 Correct 15 ms 5340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 5 ms 5076 KB Output is correct
3 Correct 5 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 7 ms 5076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 7 ms 5076 KB Output is correct
9 Correct 15 ms 5340 KB Output is correct
10 Correct 22 ms 4948 KB Output is correct
11 Execution timed out 5072 ms 6228 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 5 ms 5076 KB Output is correct
3 Correct 5 ms 5076 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 7 ms 5076 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 7 ms 5076 KB Output is correct
9 Correct 15 ms 5340 KB Output is correct
10 Correct 22 ms 4948 KB Output is correct
11 Execution timed out 5072 ms 6228 KB Time limit exceeded
12 Halted 0 ms 0 KB -