Submission #622795

# Submission time Handle Problem Language Result Execution time Memory
622795 2022-08-04T14:36:40 Z Hanksburger Tropical Garden (IOI11_garden) C++17
100 / 100
142 ms 51428 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
int dist[300005], dist2[300005], ind[150005], ind2[150005], mn[150005], mn2[150005], ans[2005];
vector<int> vec[300005], tor[300005], tor2[300005];
vector<pair<int, int> > adj[150005];
queue<int> q;
void count_routes(int n, int m, int p, int r[][2], int k, int g[])
{
    for (int i=0; i<m; i++)
    {
        adj[r[i][0]].push_back({r[i][1], i});
        adj[r[i][1]].push_back({r[i][0], i});
    }
    for (int i=0; i<n; i++)
    {
        ind[i]=adj[i][0].first;
        mn[i]=adj[i][0].second;
        if (adj[i].size()==1)
        {
            ind2[i]=adj[i][0].first;
            mn2[i]=adj[i][0].second;
        }
        else
        {
            mn2[i]=1e9;
            for (int j=1; j<adj[i].size(); j++)
            {
//                cout << "i j " << i << ' ' << j << ' ' << adj[i][j].first << ' ' << adj[i][j].second << '\n';
                if (mn[i]>adj[i][j].second)
                {
                    ind2[i]=ind[i];
                    mn2[i]=mn[i];
                    ind[i]=adj[i][j].first;
                    mn[i]=adj[i][j].second;
                }
                else if (mn2[i]>adj[i][j].second)
                {
                    ind2[i]=adj[i][j].first;
                    mn2[i]=adj[i][j].second;
                }
            }
//            cout << "ind " << i << ": " << ind[i] << ' ' << ind2[i] << '\n';
        }
    }
    for (int i=0; i<n; i++)
    {
        if (ind[ind[i]]==i && ind2[ind[i]]!=i)
            vec[ind[i]+n].push_back(i);
        else
            vec[ind[i]].push_back(i);
        if (ind[ind2[i]]==i && ind2[ind2[i]]!=i)
            vec[ind2[i]+n].push_back(i+n);
        else
            vec[ind2[i]].push_back(i+n);
    }
//    for (int i=0; i<n*2; i++)
//        for (int v:vec[i])
//            cout << v << ' ' << i << '\n';
    q.push(p);
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
//        cout << "u=" << u << '\n';
        for (int v:vec[u])
        {
            if (!dist[v])
            {
                dist[v]=dist[u]+1;
                q.push(v);
            }
        }
    }
    q.push(p+n);
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
//        cout << "u=" << u << '\n';
        for (int v:vec[u])
        {
            if (!dist2[v])
            {
                dist2[v]=dist2[u]+1;
                q.push(v);
            }
        }
    }
    if (dist[p])
    {
        for (int i=0; i<n; i++)
            if (dist[i])
                tor[dist[i]%dist[p]].push_back(dist[i]);
        for (int i=0; i<dist[p]; i++)
            sort(tor[i].begin(), tor[i].end());
        for (int i=0; i<k; i++)
        {
            int x=g[i]%dist[p];
            ans[i]+=upper_bound(tor[x].begin(), tor[x].end(), g[i])-tor[x].begin();
        }
    }
    else
    {
        for (int i=0; i<n; i++)
            if (dist[i])
                tor[dist[i]].push_back(dist[i]);
        for (int i=0; i<k; i++)
            if (g[i]<=n*2)
                ans[i]+=tor[g[i]].size();
    }
    if (dist2[p+n])
    {
        for (int i=0; i<n; i++)
            if (dist2[i])
                tor2[dist2[i]%dist2[p+n]].push_back(dist2[i]);
        for (int i=0; i<dist2[p+n]; i++)
            sort(tor2[i].begin(), tor2[i].end());
        for (int i=0; i<k; i++)
        {
            int x=g[i]%dist2[p+n];
            ans[i]+=upper_bound(tor2[x].begin(), tor2[x].end(), g[i])-tor2[x].begin();
        }
    }
    else
    {
        for (int i=0; i<n; i++)
            if (dist2[i])
                tor2[dist2[i]].push_back(dist2[i]);
        for (int i=0; i<k; i++)
            if (g[i]<=n*2)
                ans[i]+=tor2[g[i]].size();
    }
    for (int i=0; i<k; i++)
        answer(ans[i]);
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:28:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             for (int j=1; j<adj[i].size(); j++)
      |                           ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25044 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 18 ms 25044 KB Output is correct
4 Correct 14 ms 24992 KB Output is correct
5 Correct 13 ms 25020 KB Output is correct
6 Correct 13 ms 25164 KB Output is correct
7 Correct 13 ms 24916 KB Output is correct
8 Correct 13 ms 25044 KB Output is correct
9 Correct 15 ms 25340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25044 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 18 ms 25044 KB Output is correct
4 Correct 14 ms 24992 KB Output is correct
5 Correct 13 ms 25020 KB Output is correct
6 Correct 13 ms 25164 KB Output is correct
7 Correct 13 ms 24916 KB Output is correct
8 Correct 13 ms 25044 KB Output is correct
9 Correct 15 ms 25340 KB Output is correct
10 Correct 15 ms 24908 KB Output is correct
11 Correct 21 ms 27388 KB Output is correct
12 Correct 38 ms 29268 KB Output is correct
13 Correct 71 ms 41656 KB Output is correct
14 Correct 110 ms 39476 KB Output is correct
15 Correct 119 ms 41040 KB Output is correct
16 Correct 134 ms 36436 KB Output is correct
17 Correct 102 ms 35796 KB Output is correct
18 Correct 34 ms 29892 KB Output is correct
19 Correct 114 ms 41872 KB Output is correct
20 Correct 135 ms 42816 KB Output is correct
21 Correct 94 ms 37844 KB Output is correct
22 Correct 99 ms 37356 KB Output is correct
23 Correct 98 ms 42268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 25044 KB Output is correct
2 Correct 13 ms 25044 KB Output is correct
3 Correct 18 ms 25044 KB Output is correct
4 Correct 14 ms 24992 KB Output is correct
5 Correct 13 ms 25020 KB Output is correct
6 Correct 13 ms 25164 KB Output is correct
7 Correct 13 ms 24916 KB Output is correct
8 Correct 13 ms 25044 KB Output is correct
9 Correct 15 ms 25340 KB Output is correct
10 Correct 15 ms 24908 KB Output is correct
11 Correct 21 ms 27388 KB Output is correct
12 Correct 38 ms 29268 KB Output is correct
13 Correct 71 ms 41656 KB Output is correct
14 Correct 110 ms 39476 KB Output is correct
15 Correct 119 ms 41040 KB Output is correct
16 Correct 134 ms 36436 KB Output is correct
17 Correct 102 ms 35796 KB Output is correct
18 Correct 34 ms 29892 KB Output is correct
19 Correct 114 ms 41872 KB Output is correct
20 Correct 135 ms 42816 KB Output is correct
21 Correct 94 ms 37844 KB Output is correct
22 Correct 99 ms 37356 KB Output is correct
23 Correct 98 ms 42268 KB Output is correct
24 Correct 49 ms 24988 KB Output is correct
25 Correct 22 ms 27632 KB Output is correct
26 Correct 55 ms 29940 KB Output is correct
27 Correct 57 ms 42600 KB Output is correct
28 Correct 98 ms 41860 KB Output is correct
29 Correct 119 ms 42780 KB Output is correct
30 Correct 120 ms 38316 KB Output is correct
31 Correct 86 ms 37468 KB Output is correct
32 Correct 37 ms 29924 KB Output is correct
33 Correct 94 ms 41688 KB Output is correct
34 Correct 142 ms 42880 KB Output is correct
35 Correct 128 ms 38220 KB Output is correct
36 Correct 110 ms 37524 KB Output is correct
37 Correct 105 ms 42168 KB Output is correct
38 Correct 101 ms 51428 KB Output is correct