Submission #115869

# Submission time Handle Problem Language Result Execution time Memory
115869 2019-06-09T12:09:39 Z oolimry Tropical Garden (IOI11_garden) C++14
69 / 100
1581 ms 11060 KB
#include "garden.h"
#include "gardenlib.h"

#include <bits/stdc++.h>
using namespace std;

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    int n = N, m = M;
    typedef pair<int,int> ii;
    ii beautiful[N];
    fill(beautiful,beautiful+N,ii(-1,-1));
    for(int i = 0;i < m;i++){
        int a = R[i][0];
        int b = R[i][1];
        if(beautiful[a].first == -1) beautiful[a].first = b;
        else if(beautiful[a].second == -1) beautiful[a].second = b;
        if(beautiful[b].first == -1) beautiful[b].first = a;
        else if(beautiful[b].second == -1) beautiful[b].second = a;
    }
    for(int i = 0;i < n;i++){
        if(beautiful[i].second == -1) beautiful[i].second = beautiful[i].first;
        //cout << beautiful[i].first << " " << beautiful[i].second << "\n";
    }

    int big = 1000000000;

    int dis[2*n];
    int reach[2*n];
    fill(dis,dis+2*n,-1);
    fill(reach,reach+2*n,-1);
    dis[P] = 0;
    dis[P+N] = 0;
    reach[P] = 1;
    reach[P+N] = 2;
    for(int i = 0;i < 2 * n;i++){
        int a = i;
        set<int> vis;
        stack<int> order;

        while(true){
            //cout << a << " ";
            if(dis[a] != -1){
                int c = 1;
                while(!order.empty()){
                    dis[order.top()] = dis[a] + c;
                    reach[order.top()] = reach[a];
                    order.pop();
                    c++;
                }
                break;
            }
            else if(vis.find(a) != vis.end()){
                while(!order.empty()){
                    dis[order.top()] = big + 7;
                    reach[order.top()] = 0;
                    order.pop();
                }
            }
            vis.insert(a);
            order.push(a);

            int b;
            if(a < n){
                b = beautiful[a].first;
            }
            else{
                a -= n;
                b = beautiful[a].second;
            }
            if(beautiful[b].first == a){
                b += n;
            }
            a = b;
        }
        //cout << "\n";
    }

    for(int i = 0;i < 2 * n;i++){
        //cout << dis[i] << " ";
    }

    ii ptowhere;
    ii nptowhere;

    int a = P;
    set<int> vis;
    while(true){
        ///edit this
        if(a == P + N){
            ptowhere = ii(2,vis.size());
            break;
        }
        if(vis.find(a) != vis.end()){
            if(a == P){
                ptowhere = ii(1,vis.size());
            }
            else{
                ptowhere = ii(0,-1);
            }
            break;
        }
        vis.insert(a);


        int b;
        if(a < n){
            b = beautiful[a].first;
        }
        else{
            a -= n;
            b = beautiful[a].second;
        }
        if(beautiful[b].first == a){
            b += n;
        }
        a = b;
    }


    a = P+N;
    vis.clear();
    while(true){
        if(a == P){
            nptowhere = ii(1,vis.size());
            break;
        }
        if(vis.find(a) != vis.end()){
            if(a == P + N){
                nptowhere = ii(2,vis.size());
            }
            else{
                nptowhere = ii(0,-1);
            }
            break;
        }
        vis.insert(a);


        int b;
        if(a < n){
            b = beautiful[a].first;
        }
        else{
            a -= n;
            b = beautiful[a].second;
        }
        if(beautiful[b].first == a){
            b += n;
        }
        a = b;
    }
    //cout << ptowhere.first << " " << ptowhere.second << " " << nptowhere.first << " " << nptowhere.second;


    if(ptowhere.first == 2 && nptowhere.first == 1){
        for(int qq = 0;qq < Q;qq++){
            int x = G[qq];
            int ans = 0;

            for(int i = 0;i < n;i++){
                if(x - dis[i] >= 0 && (x - dis[i]) % (ptowhere.second + nptowhere.second) == 0){
                    ans++;
                    continue;
                }
                if(reach[i] == 1){
                    if((x - dis[i] - ptowhere.second) >= 0 && (x - dis[i] - ptowhere.second) % (ptowhere.second + nptowhere.second) == 0){
                        ans++;
                        continue;
                    }
                }
                else if(reach[i] = 2){
                    if((x - dis[i] - nptowhere.second) >= 0 && (x - dis[i] - nptowhere.second) % (ptowhere.second + nptowhere.second) == 0){
                        ans++;
                        continue;
                    }
                }
            }
            answer(ans);
        }
    }
    else{
        for(int qq = 0;qq < Q;qq++){
            int x = G[qq];
            int ans = 0;
            for(int i = 0;i < n;i++){


                if(reach[i] == 1){

                    if(dis[i] == x){
                        ans++;
                        continue;
                    }
                    if(ptowhere.first == 1){
                        if(x - dis[i] >= 0 && (x-dis[i]) % ptowhere.second == 0){
                            ans++;
                            continue;
                        }
                    }
                    else if(ptowhere.first == 2){

                        if(nptowhere.first == 0){
                            if(dis[i] + ptowhere.second == x){
                                ans++;
                                continue;
                            }
                        }
                        else if(nptowhere.first == 2){
                            if((x - dis[i] - ptowhere.second) >= 0 && (x - dis[i] - ptowhere.second) % nptowhere.second == 0){
                                ans++;
                                continue;
                            }
                        }
                    }
                }
                else if(reach[i] = 2){
                    if(dis[i] == x){
                        ans++;
                        continue;
                    }
                    if(nptowhere.first == 2){
                        if(x - dis[i] >= 0 && (x-dis[i]) % nptowhere.second == 0){
                            ans++;
                            continue;
                        }
                    }
                    else if(nptowhere.first == 1){
                        if(ptowhere.first == 0){
                            if(dis[i] + nptowhere.second == x){
                                ans++;
                                continue;
                            }
                        }
                        else if(ptowhere.first == 2){
                            if((x-dis[i]-nptowhere.second) >= 0 && (x-dis[i]-nptowhere.second) % ptowhere.second == 0){
                                ans++;
                                continue;
                            }
                        }
                    }
                }
            }
            answer(ans);
        }
    }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:172:34: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
                 else if(reach[i] = 2){
                         ~~~~~~~~~^~~
garden.cpp:217:34: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
                 else if(reach[i] = 2){
                         ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 18 ms 1272 KB Output is correct
12 Correct 29 ms 2012 KB Output is correct
13 Correct 115 ms 11004 KB Output is correct
14 Correct 104 ms 4704 KB Output is correct
15 Correct 88 ms 4508 KB Output is correct
16 Correct 75 ms 3736 KB Output is correct
17 Correct 84 ms 3260 KB Output is correct
18 Correct 31 ms 1656 KB Output is correct
19 Correct 99 ms 4668 KB Output is correct
20 Correct 95 ms 4700 KB Output is correct
21 Correct 75 ms 3640 KB Output is correct
22 Correct 72 ms 3240 KB Output is correct
23 Correct 106 ms 5340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 2 ms 352 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 18 ms 1272 KB Output is correct
12 Correct 29 ms 2012 KB Output is correct
13 Correct 115 ms 11004 KB Output is correct
14 Correct 104 ms 4704 KB Output is correct
15 Correct 88 ms 4508 KB Output is correct
16 Correct 75 ms 3736 KB Output is correct
17 Correct 84 ms 3260 KB Output is correct
18 Correct 31 ms 1656 KB Output is correct
19 Correct 99 ms 4668 KB Output is correct
20 Correct 95 ms 4700 KB Output is correct
21 Correct 75 ms 3640 KB Output is correct
22 Correct 72 ms 3240 KB Output is correct
23 Correct 106 ms 5340 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 129 ms 1360 KB Output is correct
26 Correct 171 ms 1940 KB Output is correct
27 Correct 1470 ms 11060 KB Output is correct
28 Correct 1339 ms 4680 KB Output is correct
29 Correct 1581 ms 4752 KB Output is correct
30 Correct 979 ms 3780 KB Output is correct
31 Correct 884 ms 3248 KB Output is correct
32 Correct 156 ms 1760 KB Output is correct
33 Correct 1391 ms 4676 KB Output is correct
34 Correct 1476 ms 4856 KB Output is correct
35 Incorrect 963 ms 3748 KB Output isn't correct
36 Halted 0 ms 0 KB -