Submission #203152

# Submission time Handle Problem Language Result Execution time Memory
203152 2020-02-19T14:55:11 Z alexandra_udristoiu Tropical Garden (IOI11_garden) C++14
69 / 100
5000 ms 25976 KB
#include<fstream>
#include<vector>
#include<cstring>
#include "garden.h"
#include "gardenlib.h"
#define DIM 300005
using namespace std;
static int viz[DIM], dist[DIM], t[DIM], cic[DIM], nrcic[DIM], pos[DIM];
static pair<int, int> p[DIM][2];
static vector<int> v[DIM];
static void dfs(int nod){
    viz[nod] = 1;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i];
        if(viz[vecin] == 0){
            dist[vecin] = 1 + dist[nod];
            dfs(vecin);
        }
    }
}
static void calcp(int i, int x, int y){
    if(p[x][0].first == 0){
        p[x][0] = make_pair(i, y);
    }
    else{
        if(p[x][1].first == 0){
            p[x][1] = make_pair(i, y);
        }
    }
}
static void calct(int x, pair<int, int> curr){
    if(p[ curr.second ][0].first == curr.first && p[ curr.second ][1].first != 0){
        t[x] = 2 * curr.second;
    }
    else{
        t[x] = 2 * curr.second - 1;
    }
}
void count_routes(int n, int m, int d, int w[][2], int q, int g[]){
    int i, x, k, j, sol;
    d++;
    for(i = 0; i < m; i++){
        w[i][0]++;
        w[i][1]++;
        calcp(i + 1, w[i][0], w[i][1]);
        calcp(i + 1, w[i][1], w[i][0]);
    }
    for(i = 1; i <= n; i++){
        calct(2 * i - 1, p[i][0]);
        if(p[i][1].first != 0){
            calct(2 * i, p[i][1]);
        }
        else{
            t[2 * i] = 2 * i;
        }
    }
    k = 0;
    for(i = 1; i <= 2 * n; i++){
        v[ t[i] ].push_back(i);
        x = i;
        while(viz[x] == 0){
            viz[x] = 1;
            pos[x] = i;
            x = t[x];
        }
        if(pos[x] == i){
            k++;
            while(viz[x] != 2){
                viz[x] = 2;
                cic[x] = k;
                nrcic[k]++;
                x = t[x];
            }
        }
    }
    for(i = 0; i < q; i++){
        sol = 0;
        for(x = 2 * d - 1; x <= 2 * d; x++){
            memset(viz, 0, sizeof(viz) );
            dist[x] = 0;
            dfs(x);
            for(j = 1; j <= 2 * n; j += 2){
                if(cic[x] != 0){
                    if(viz[j] == 1 && dist[j] <= g[i] && (dist[j] - g[i]) % nrcic[ cic[x] ] == 0){
                        sol++;
                    }
                }
                else{
                    if(viz[j] == 1 && dist[j] == g[i]){
                        sol++;
                    }
                }
            }
        }
        answer(sol);
    }
}

Compilation message

garden.cpp: In function 'void dfs(int)':
garden.cpp:13:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v[nod].size(); i++){
                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8696 KB Output is correct
2 Correct 10 ms 8696 KB Output is correct
3 Correct 10 ms 8696 KB Output is correct
4 Correct 10 ms 8568 KB Output is correct
5 Correct 10 ms 8568 KB Output is correct
6 Correct 11 ms 8696 KB Output is correct
7 Correct 10 ms 8568 KB Output is correct
8 Correct 10 ms 8696 KB Output is correct
9 Correct 12 ms 8700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8696 KB Output is correct
2 Correct 10 ms 8696 KB Output is correct
3 Correct 10 ms 8696 KB Output is correct
4 Correct 10 ms 8568 KB Output is correct
5 Correct 10 ms 8568 KB Output is correct
6 Correct 11 ms 8696 KB Output is correct
7 Correct 10 ms 8568 KB Output is correct
8 Correct 10 ms 8696 KB Output is correct
9 Correct 12 ms 8700 KB Output is correct
10 Correct 10 ms 8696 KB Output is correct
11 Correct 20 ms 11000 KB Output is correct
12 Correct 34 ms 12280 KB Output is correct
13 Correct 54 ms 23928 KB Output is correct
14 Correct 116 ms 24252 KB Output is correct
15 Correct 148 ms 24396 KB Output is correct
16 Correct 111 ms 19632 KB Output is correct
17 Correct 96 ms 17912 KB Output is correct
18 Correct 34 ms 12920 KB Output is correct
19 Correct 119 ms 24312 KB Output is correct
20 Correct 146 ms 24440 KB Output is correct
21 Correct 106 ms 19448 KB Output is correct
22 Correct 106 ms 17888 KB Output is correct
23 Correct 126 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8696 KB Output is correct
2 Correct 10 ms 8696 KB Output is correct
3 Correct 10 ms 8696 KB Output is correct
4 Correct 10 ms 8568 KB Output is correct
5 Correct 10 ms 8568 KB Output is correct
6 Correct 11 ms 8696 KB Output is correct
7 Correct 10 ms 8568 KB Output is correct
8 Correct 10 ms 8696 KB Output is correct
9 Correct 12 ms 8700 KB Output is correct
10 Correct 10 ms 8696 KB Output is correct
11 Correct 20 ms 11000 KB Output is correct
12 Correct 34 ms 12280 KB Output is correct
13 Correct 54 ms 23928 KB Output is correct
14 Correct 116 ms 24252 KB Output is correct
15 Correct 148 ms 24396 KB Output is correct
16 Correct 111 ms 19632 KB Output is correct
17 Correct 96 ms 17912 KB Output is correct
18 Correct 34 ms 12920 KB Output is correct
19 Correct 119 ms 24312 KB Output is correct
20 Correct 146 ms 24440 KB Output is correct
21 Correct 106 ms 19448 KB Output is correct
22 Correct 106 ms 17888 KB Output is correct
23 Correct 126 ms 25976 KB Output is correct
24 Correct 168 ms 8656 KB Output is correct
25 Correct 389 ms 11384 KB Output is correct
26 Correct 414 ms 12920 KB Output is correct
27 Execution timed out 5016 ms 24824 KB Time limit exceeded
28 Halted 0 ms 0 KB -