CODE THANKS FESTIVAL 2018(Parallel)

Submission #10033340

Source codeソースコード

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M,K; cin >> N >> M >> K;
    vector<vector<int>> G(N);
    int s;
    rep(i,N) {
        int p; cin >> p;
        p--;
        if (p < 0) {
            s = i;
            continue;
        }
        G[p].emplace_back(i);
    }

    vector<int> dist(N);
    queue<int> que;
    que.emplace(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            dist[nv] = dist[v]+1;
            que.emplace(nv);
        }
    }
    if (K < M) {
        cout << -1 << endl;
        return 0;
    }
    K -= M;
    reverse(all(dist));
    vector<bitset<100001>> dp(M+1);
    dp[0][0] = 1;
    rep(i,N) {
        for (int j = M; j > 0; --j) {
            dp[j] |= (dp[j-1]<<dist[i]);
        }
    }
    if (!dp[M].test(K)) {
        cout << -1 << endl;
        return 0;
    }
    reverse(all(dist));
    vector<int> ans;
    rep(i,N) {
        if (M > 0 && K - dist[i] >= 0 && dp[M-1].test(K-dist[i])) {
            ans.emplace_back(i+1);
            K -= dist[i];
            M--;
        }
    }

    for (auto i : ans) cout << i << " ";
    cout << endl;

}

Submission

Task問題 F - Coins on the tree
User nameユーザ名 minato_
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1925 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - s1.txt,s2.txt
All 0 / 400 01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,31.txt,32.txt,33.txt,34.txt,35.txt,36.txt,37.txt,38.txt,39.txt,40.txt,s1.txt,s2.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01.txt WA
02.txt AC 2 ms 384 KB
03.txt WA
04.txt WA
05.txt WA
06.txt WA
07.txt WA
08.txt WA
09.txt WA
10.txt WA
11.txt WA
12.txt WA
13.txt WA
14.txt WA
15.txt WA
16.txt WA
17.txt WA
18.txt WA
19.txt WA
20.txt WA
21.txt WA
22.txt WA
23.txt WA
24.txt WA
25.txt WA
26.txt WA
27.txt WA
28.txt WA
29.txt WA
30.txt WA
31.txt AC 15 ms 640 KB
32.txt AC 3 ms 512 KB
33.txt AC 12 ms 640 KB
34.txt AC 3 ms 512 KB
35.txt AC 34 ms 640 KB
36.txt WA
37.txt WA
38.txt WA
39.txt WA
40.txt WA
s1.txt AC 1 ms 384 KB
s2.txt AC 1 ms 384 KB