답안 #963137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963137 2024-04-14T15:00:14 Z Amr 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
49 / 100
6 ms 5036 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define sz size()
#define all(x) (x).begin(),(x).end()
const int N = 1002;
const int Log = 32;
vector<pair<ll,ll> > v[N];
ll lst[N];
vector<ll> vec;
ll vis[N];
pair<ll,ll> sp[N][Log][2];
void dfs1(ll x)
{
    if(vis[x]) return;
    vis[x] = 1;
    vec.push_back(x);
    for(int i = 0; i < v[x].sz; i++)
    {
        dfs1(v[x][i].S);
    }
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    for(int i = 0; i < M; i++)
    {
        ll x = R[i][0] , y = R[i][1];
        v[x].push_back({i,y});
        v[y].push_back({i,x});
    }
    for(int i = 0; i < N; i++) sort(all(v[i]));


    dfs1(P);
    if(vec.sz==2)
    {
        answer(1);
        return;
    }
    for(int i = 0; i < vec.sz; i++)
    {
        ll x = vec[i];
        ll y = v[x][0].S;
        ll m = -1;
        if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1;
        sp[x][0][0] = {y,m};


        if(v[x].sz==1) {sp[x][0][1] = {-1,-1}; continue;}

        m = -1;
        y = v[x][1].S;
        if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1;
        sp[x][0][1] = {y,m};
    }
    for(int j = 1; j < Log; j++)
    {
        for(int i = 0; i < vec.sz; i++)
        {
            ll x = vec[i];
            ll y = sp[x][j-1][0].F,m=0;

            if(sp[sp[x][j-1][0].F][j-1][1].F!=-1&&sp[x][j-1][0].S==0) m = 1;
            sp[x][j][0] = sp[sp[x][j-1][0].F][j-1][m];
            if(sp[x][0][1].F!=-1)
            {
                ll y = sp[x][j-1][0].F,m=0;
                if(sp[sp[x][j-1][1].F][j-1][1].F!=-1&&sp[x][j-1][1].S==0) m = 1;
                sp[x][j][1] = sp[sp[x][j-1][1].F][j-1][m];
            }
            else sp[x][j][1] = {-1,-1};
        }
    }
    /*for(int i = 0; i < N; i++){

        for(int j = 0; j < 3; j++)
        {
            cout << sp[i][j][0].F <<  " " << sp[i][j][1].F << endl;
        }
        cout << endl;
    }*/


        ll ans = 0;
        for(int i = 0; i < vec.sz; i++)
        {
            ll x = vec[i], y = 0;
            ll k = G[0];
            for(int j = Log-1; j >= 0; j--)
            {
                if(k<(1LL<<j)) continue;
                k-=(1LL<<j);
                ll x2 = sp[x][j][y].F,m = sp[x][j][y].S;
                if(m==0&&sp[x2][0][1].F!=-1) m = 1; else m = 0;
                x = x2, y = m;
            }
            //cout << x << " ";
            if(x==P) ans++;
        }
        answer(ans);


}

Compilation message

garden.cpp: In function 'void dfs1(ll)':
garden.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < v[x].sz; i++)
      |                      ^
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i = 0; i < vec.sz; i++)
      |                      ^
garden.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int i = 0; i < vec.sz; i++)
      |                          ^
garden.cpp:71:20: warning: unused variable 'y' [-Wunused-variable]
   71 |                 ll y = sp[x][j-1][0].F,m=0;
      |                    ^
garden.cpp:65:16: warning: unused variable 'y' [-Wunused-variable]
   65 |             ll y = sp[x][j-1][0].F,m=0;
      |                ^
garden.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(int i = 0; i < vec.sz; i++)
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 3 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 3 ms 3020 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Runtime error 6 ms 5036 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 3 ms 3020 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Runtime error 6 ms 5036 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -