답안 #34400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34400 2017-11-10T22:58:48 Z imaxblue File Paths (BOI15_fil) C++14
100 / 100
446 ms 4720 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

int n, m, k, t, a, b;
ll d[6005];
vector<pii> v[6005], w;
vector<ll> s;
vector<int> cyc;
vector<int> f[6005];
bool p[1000005], win[1000005], u[6005];
void factor(int P, ll D){
    for(int l=1; 1LL*l*l<=D; ++l){
        if (D%l==0){
            //cout << "%" << D << ' ' << l << endl;
            f[P].pb(l);
            f[P].pb(D/l);
        }
    }
}
void dfs2(int N, ll D){
    fox(l, v[N].size()){
        dfs2(v[N][l].x, D+v[N][l].y);
    }
    if (N<=n && D+t<=k)
        p[D+t]=1;
}
void dfs3(int N, ll D){
    fox(l, v[N].size()){
        dfs3(v[N][l].x, D+v[N][l].y);
    }
    if (N>n && !u[N] && d[N]<=k){
        w.pb(mp(k-d[N], N));
    } else if (N<=n && D+t<=k){
        cyc.pb(D+t);
    }
}
void dfs(int N, ll D){
    if (N>n){
        d[N]=D;
        //cout << N << ' ' << D << endl;
        //fox(l, s.size()) cout << s[l] << ' '; cout << endl;
        if (D==k){
            u[N]=1; return;
        }
        fox(l, s.size())
            if (D-s[l]<=k && p[k-(D-s[l])]){
                u[N]=1; return;
            }
        if (D<=k)
            factor(N, k-D);
        //cout << N << ' ' << D <<"^" << endl;
        //fox(l, f[N].size()) cout << f[N][l] << ' '; cout << endl;
        return;
    }
    s.pb(D);
    fox(l, v[N].size()){
        dfs(v[N][l].x, D+v[N][l].y);
    }
    s.pop_back();

    w.clear(); cyc.clear();
    dfs3(N, 0);
    sort(w.begin(), w.end());
    fox(l, cyc.size()){
        win[cyc[l]]=1;
    }
    //cout << N << "*" << endl;
    //fox(l, w.size()) cout << w[l].x << ' '; cout << endl;
    fox(l, w.size()){
        if (l>0 && w[l].x==w[l-1].x){
            if (u[w[l-1].y]) u[w[l].y]=1;
            continue;
        }
        fox(l2, f[w[l].y].size()){
            if (win[f[w[l].y][l2]]){
                u[w[l].y]=1;
                break;
            }
        }
    }
    fox(l, cyc.size()){
        win[cyc[l]]=0;
    }
}
int main(){
    cin >> n >> m >> k >> t;
    ++t;
    fox1(l, n){
        cin >> a >> b;
        v[a].pb(mp(l, b+1));
    }
    fox1(l, m){
        cin >> a >> b;
        v[a].pb(mp(l+n, b+1));
    }
    dfs2(0, 0);
    dfs(0, 0);
    fox1(l, m){
        if (u[l+n]) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

Compilation message

fil.cpp: In function 'void dfs2(int, long long int)':
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:44:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
fil.cpp: In function 'void dfs3(int, long long int)':
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:51:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
fil.cpp: In function 'void dfs(int, long long int)':
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:68:9: note: in expansion of macro 'fox'
         fox(l, s.size())
         ^
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:79:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:87:5: note: in expansion of macro 'fox'
     fox(l, cyc.size()){
     ^
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:92:5: note: in expansion of macro 'fox'
     fox(l, w.size()){
     ^
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:97:9: note: in expansion of macro 'fox'
         fox(l2, f[w[l].y].size()){
         ^
fil.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fil.cpp:104:5: note: in expansion of macro 'fox'
     fox(l, cyc.size()){
     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4308 KB Output is correct
2 Correct 0 ms 4308 KB Output is correct
3 Correct 0 ms 4308 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 4440 KB Output is correct
6 Correct 6 ms 4440 KB Output is correct
7 Correct 9 ms 4440 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 0 ms 4308 KB Output is correct
11 Correct 0 ms 4308 KB Output is correct
12 Correct 6 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4572 KB Output is correct
2 Correct 16 ms 4572 KB Output is correct
3 Correct 13 ms 4572 KB Output is correct
4 Correct 16 ms 4572 KB Output is correct
5 Correct 283 ms 4648 KB Output is correct
6 Correct 253 ms 4640 KB Output is correct
7 Correct 199 ms 4572 KB Output is correct
8 Correct 173 ms 4572 KB Output is correct
9 Correct 16 ms 4572 KB Output is correct
10 Correct 16 ms 4572 KB Output is correct
11 Correct 9 ms 4440 KB Output is correct
12 Correct 369 ms 4672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4308 KB Output is correct
2 Correct 0 ms 4308 KB Output is correct
3 Correct 0 ms 4308 KB Output is correct
4 Correct 6 ms 4308 KB Output is correct
5 Correct 6 ms 4440 KB Output is correct
6 Correct 6 ms 4440 KB Output is correct
7 Correct 9 ms 4440 KB Output is correct
8 Correct 3 ms 4308 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 0 ms 4308 KB Output is correct
11 Correct 0 ms 4308 KB Output is correct
12 Correct 6 ms 4308 KB Output is correct
13 Correct 9 ms 4572 KB Output is correct
14 Correct 16 ms 4572 KB Output is correct
15 Correct 13 ms 4572 KB Output is correct
16 Correct 16 ms 4572 KB Output is correct
17 Correct 283 ms 4648 KB Output is correct
18 Correct 253 ms 4640 KB Output is correct
19 Correct 199 ms 4572 KB Output is correct
20 Correct 173 ms 4572 KB Output is correct
21 Correct 16 ms 4572 KB Output is correct
22 Correct 16 ms 4572 KB Output is correct
23 Correct 9 ms 4440 KB Output is correct
24 Correct 369 ms 4672 KB Output is correct
25 Correct 13 ms 4572 KB Output is correct
26 Correct 13 ms 4572 KB Output is correct
27 Correct 9 ms 4572 KB Output is correct
28 Correct 13 ms 4572 KB Output is correct
29 Correct 246 ms 4640 KB Output is correct
30 Correct 253 ms 4644 KB Output is correct
31 Correct 193 ms 4716 KB Output is correct
32 Correct 189 ms 4720 KB Output is correct
33 Correct 13 ms 4572 KB Output is correct
34 Correct 9 ms 4572 KB Output is correct
35 Correct 6 ms 4440 KB Output is correct
36 Correct 446 ms 4688 KB Output is correct