답안 #586875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586875 2022-06-30T21:25:38 Z MohammadAghil File Paths (BOI15_fil) C++17
0 / 100
367 ms 262144 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      freopen("in.in", "r", stdin);
     //      freopen("out.out", "w", stdout);
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 6e3 + 5, maxk = 1e6 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int l[maxn], par[maxn], n, m, k, s;
vector<int> adj[maxn];
int vl[maxk], vl2[maxk];
bool ans[maxn];

vector<int> res;
void dfs3(int r, int h = s){
     if(r > n) return;
     res.pb(h);
     for(int c: adj[r]) dfs3(c, h + l[c]);
}

void dfs2(int r, int x, int h = 0){
     if(r == x || r > n) return;
     res.pb(h + s);
     for(int c: adj[r]) dfs2(c, x, h + l[c]); 
}

void add(int u, int h){
     res.clear();
     dfs3(u);
     for(int c: res) vl[c]++;
     res.clear();
     dfs2(0, u);
     for(ll c: res) if(c > h) vl2[c-h]++; 
}

void del(int u, int h){
     res.clear();
     dfs3(u);
     for(int c: res) vl[c]--;
     res.clear();
     dfs2(0, u);
     for(ll c: res) if(c > h) vl2[c-h]--; 
}

void dfs(int r, int h = 0){
     if(r > n){ r -= n;
          ll t = k - h;
          ans[r] = vl2[t] || t == 0; 
          if(!ans[r]){
               for(int j = 1; j*j <= t; j++){
                    if(t%j == 0){
                         if(vl[j] || vl[t/j]){
                              ans[r] = true;
                              break;
                         }
                    }
               }
          }
     }else{
          add(r, h);
          for(int c: adj[r]) dfs(c, h + l[c]);
          del(r, h);
     }
}

int main(){ IOS();
     // rep(i,1,maxk) for(int j = i; j < maxk; j += i) dv[j].pb(i);
     par[0] = -1;
     cin >> n >> m >> k >> s; s++;
     rep(i,1,n+m+1) cin >> par[i] >> l[i], adj[par[i]].pb(i), l[i]++;
     dfs(0);
     rep(i,1,m+1) cout << (ans[i]?"YES\n":"NO\n");
     return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Runtime error 367 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 6868 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 5 ms 1364 KB Output is correct
5 Runtime error 367 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -