Submission #542661

#TimeUsernameProblemLanguageResultExecution timeMemory
542661alextodoranFriend (IOI14_friend)C++17
100 / 100
25 ms3444 KiB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int I_AM_YOUR_FRIEND = 0;
const int MY_FRIENDS_ARE_YOUR_FRIENDS = 1;
const int WE_ARE_YOUR_FRIENDS = 2;

int findSample (int n, int confidence[], int host[], int protocol[]) {
    int take[n], skip[n];
    for (int u = 0; u < n; u++) {
        take[u] = confidence[u];
        skip[u] = 0;
    }
    for (int u = n - 1; u > 0; u--) {
        int v = host[u];
        int newTake;
        int newSkip;
        if (protocol[u] == I_AM_YOUR_FRIEND) {
            newTake = take[v] + skip[u];
            newSkip = skip[v] + max(take[u], skip[u]);
        }
        if (protocol[u] == MY_FRIENDS_ARE_YOUR_FRIENDS) {
            newTake = max({take[u] + take[v], take[u] + skip[v], skip[u] + take[v]});
            newSkip = skip[u] + skip[v];
        }
        if (protocol[u] == WE_ARE_YOUR_FRIENDS) {
            newTake = max(take[u] + skip[v], skip[u] + take[v]);
            newSkip = skip[u] + skip[v];
        }
        take[v] = newTake;
        skip[v] = newSkip;
    }
    return max(take[0], skip[0]);
}

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:41:17: warning: 'newTake' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         take[v] = newTake;
      |         ~~~~~~~~^~~~~~~~~
friend.cpp:42:17: warning: 'newSkip' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |         skip[v] = newSkip;
      |         ~~~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...