Submission #622792

# Submission time Handle Problem Language Result Execution time Memory
622792 2022-08-04T14:34:50 Z Hanksburger Tropical Garden (IOI11_garden) C++17
49 / 100
140 ms 73136 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++)
            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++)
            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 13 ms 25044 KB Output is correct
2 Correct 14 ms 25044 KB Output is correct
3 Correct 13 ms 25140 KB Output is correct
4 Correct 12 ms 25000 KB Output is correct
5 Correct 13 ms 24968 KB Output is correct
6 Correct 15 ms 25196 KB Output is correct
7 Correct 13 ms 25028 KB Output is correct
8 Correct 13 ms 25048 KB Output is correct
9 Correct 15 ms 25368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25044 KB Output is correct
2 Correct 14 ms 25044 KB Output is correct
3 Correct 13 ms 25140 KB Output is correct
4 Correct 12 ms 25000 KB Output is correct
5 Correct 13 ms 24968 KB Output is correct
6 Correct 15 ms 25196 KB Output is correct
7 Correct 13 ms 25028 KB Output is correct
8 Correct 13 ms 25048 KB Output is correct
9 Correct 15 ms 25368 KB Output is correct
10 Correct 13 ms 24988 KB Output is correct
11 Correct 22 ms 27556 KB Output is correct
12 Correct 35 ms 29880 KB Output is correct
13 Correct 55 ms 42540 KB Output is correct
14 Correct 94 ms 41160 KB Output is correct
15 Correct 140 ms 42944 KB Output is correct
16 Correct 106 ms 38088 KB Output is correct
17 Runtime error 110 ms 73136 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25044 KB Output is correct
2 Correct 14 ms 25044 KB Output is correct
3 Correct 13 ms 25140 KB Output is correct
4 Correct 12 ms 25000 KB Output is correct
5 Correct 13 ms 24968 KB Output is correct
6 Correct 15 ms 25196 KB Output is correct
7 Correct 13 ms 25028 KB Output is correct
8 Correct 13 ms 25048 KB Output is correct
9 Correct 15 ms 25368 KB Output is correct
10 Correct 13 ms 24988 KB Output is correct
11 Correct 22 ms 27556 KB Output is correct
12 Correct 35 ms 29880 KB Output is correct
13 Correct 55 ms 42540 KB Output is correct
14 Correct 94 ms 41160 KB Output is correct
15 Correct 140 ms 42944 KB Output is correct
16 Correct 106 ms 38088 KB Output is correct
17 Runtime error 110 ms 73136 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -