답안 #1107684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107684 2024-11-02T00:34:33 Z laight 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
4 ms 16376 KB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pi pair<int, int>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define umi unordered_map<int, int>
#define umll unordered_map<ll, ll>
#define umllv unordered_map<ll, vector<ll>>

#define getchar() (*_pinp?*_pinp++:(_inp[fread(_pinp=_inp, 1, 4096, stdin)]='\0', *_pinp++))
char _inp[4097], *_pinp=_inp;
#define scan(x) do{while((x=getchar())<'-'); _ssign=x=='-'; if(_ssign) while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0'); x=_ssign?-x:x;}while(0)
char _; bool _ssign;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2")

using namespace std; using namespace __gnu_pbds;

const int MM = 1e5+5e4+5;
const ll inf = 2e15+1;
const int lg = 17; // 17 for 1e5, 31 for 1e9

int n, m, p, a, b, dis[2*MM], dis2[2*MM], lv, cycl, cl1, cl2, q, inp; bool cvis[2*MM], vis[2*MM], vis2[2*MM], hcy, cy1, cy2;
vector<int> g(2005), ans(2005), to(2*MM), rev[2*MM]; vector<pi> graph[MM];

void g_f(int c, int d){
    if (vis[c]) return;
    vis[c] = 1; dis[c] = d;
    for (int i : rev[c]){
        g_f(i, d+1);
    }
}
void g_f2(int c, int d){
    if (vis2[c]) return;
    vis2[c] = 1; dis2[c] = d;
    for (int i : rev[c]){
        g_f2(i, d+1);
    }
}
void cyc_f(int c, int d, int pe){
    if (cvis[c] && c == pe){
        hcy = 1; cycl = d; return;
    }
    else if (cvis[c]) return;
    cvis[c] = 1; cyc_f(to[c], d+1, pe);
}
void sol(int sp){
    memset(cvis, 0, sizeof(cvis));
    hcy = 0; cycl = 0;
    cyc_f(sp, 0, sp);
}
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
    // cin.tie(0); cin.sync_with_stdio(0);
    // freopen("changyue_tst.txt", "r", stdin);
    n = N; m = M; p = P;
    for (int i=0; i<m; ++i){
        graph[R[i][0]].pb({i+1, R[i][1]}); graph[R[i][1]].pb({i+1, R[i][0]});
    }
    q = Q; for (int i=0; i<q; i++) {g[i] = G[i];}
    for (int i=0; i<n; ++i){
        if (graph[i][0].fi == graph[graph[i][0].se][0].fi){
            to[i] = n+graph[i][0].se; rev[n+graph[i][0].se].pb(i);
        }
        else {to[i] = graph[i][0].se; rev[graph[i][0].se].pb(i);}
        if (graph[i].size() >= 2){
            if (graph[i][1].fi == graph[graph[i][1].se][0].fi){
                to[n+i] = n+graph[i][1].se; rev[n+graph[i][1].se].pb(n+i);
            }
            else {to[n+i] = graph[i][1].se; rev[graph[i][1].se].pb(n+i);}
        }
        else{
            if (graph[i][0].fi == graph[graph[i][0].se][0].fi){
                to[n+i] = n+graph[i][0].se; rev[n+graph[i][0].se].pb(n+i);
            }
            else {to[n+i] = graph[i][0].se; rev[graph[i][0].se].pb(n+i);}
        }
    }
    sol(p);
    cl1 = cycl; cy1 = hcy;
    sol(n+p);
    cl2 = cycl; cy2 = hcy;
    g_f(p, 0); g_f2(n+p, 0);
    for (int i=0; i<q; ++i){
        int tv=g[i], ca=0;
        for (int j=0; j<n; ++j){
            int addon=0;
            if (cy1){
                if (tv >= dis[j] && (tv%cl1 == dis[j]%cl1)){
                    addon = 1;
                }
            }
            else{
                if (tv == dis[j]) addon = 1;
            }
            if (cy2){
                if (tv >= dis2[j] && (tv%cl2 == dis2[j]%cl2)){
                    addon = 1;
                }
            }
            else{
                if (tv == dis2[j]) addon = 1;
            }
            ca += addon;
        }
        answer(ca);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 16376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 16376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 16376 KB Output isn't correct
2 Halted 0 ms 0 KB -