답안 #526256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526256 2022-02-14T05:47:26 Z alirezasamimi100 File Paths (BOI15_fil) C++17
0 / 100
1000 ms 174404 KB
/*#pragma GCC optimize("Ofast,unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using point=complex<double>;
#define F first
#define S second
//#define X real()
//#define Y imag()
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define kill(x) cout << x << '\n';exit(0)
#define killshayan kill("done!")
#define killmashtali kill("Hello, World!")
const int N=3e3+10,LN=19,M=1e6+10,SQ=300,BS=737,inf=1e9,NSQ=N/SQ+1;
const ll INF=1e18;
const double pi=acos(-1);
const ld ep=1e-7;
const int MH=1000696969,MD=998244353,MOD=1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,greater<pii>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n,m,k,s,cnt[M],ans[N],h[N*2],p[N*2],cn[M];
vector<pll> adj[N*2];
vector<ll> d[M];
void predfs(ll v){
    if(v<=n && h[v]+s<=k) cnt[h[v]+s]++;
    for(auto [u,w] : adj[v]){
        h[u]=h[v]+w;
        p[u]=v;
        predfs(u);
    }
}
void sfd(ll v, ll c, ll t){
    if(h[v]-c+s<=k) cn[h[v]-c+s]+=t;
    for(auto [u,w] : adj[v]){
        sfd(u,c,t);
    }
}
void dfs(ll v){
    if(v>n){
        ll x=p[v];
        while(~x){
            if(k-(h[v]-h[x])>=0 && cnt[k-(h[v]-h[x])]) ans[v-n]=1;
            x=p[x];
        }
        x=k-h[v];
        if(x==0) ans[v-n]=1;
        if(x>0){
            for(ll i : d[x]) if(cn[i]) ans[v-n]=1;
        }
        return;
    }
    sfd(v,h[v],1);
    for(auto [u,w] : adj[v]){
        dfs(u);
    }
    sfd(v,h[v],-1);
}
int main(){
    fast_io;
    for(ll i=1; i<M; i++){
        for(ll j=i; j<M; j+=i){
            d[j].pb(i);
        }
    }
    cin >> n >> m >> k >> s;
    s++;
    for(ll i=1; i<=n; i++){
        ll p,v;
        cin >> p >> v;
        adj[p].pb({i,v+1});
    }
    for(ll i=1; i<=m; i++){
        ll p,v;
        cin >> p >> v;
        adj[p].pb({i+n,v+1});
    }
    p[0]=-1;
    predfs(0);
    dfs(0);
    for(ll i=1; i<=m; i++){
        if(ans[i]) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 174404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 172968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 174404 KB Time limit exceeded
2 Halted 0 ms 0 KB -