Submission #968708

# Submission time Handle Problem Language Result Execution time Memory
968708 2024-04-23T22:20:09 Z raphaelp Paths (BOI18_paths) C++14
70 / 100
509 ms 41480 KB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long N, M, K;
    cin >> N >> M >> K;
    vector<long long> C(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> C[i];
        C[i]--;
    }
    vector<vector<long long>> AR(N);
    vector<vector<long long>> voisins(N, vector<long long>(K));
    for (long long i = 0; i < M; i++)
    {
        long long a, b;
        cin >> a >> b;
        a--, b--;
        AR[a].push_back(b);
        AR[b].push_back(a);
        voisins[a][C[b]]++;
        voisins[b][C[a]]++;
    }
    long long tot = 0, half = 0;
    for (long long i = 0; i < N; i++)
    {
        vector<long long> count((1 << K));
        for (long long j = 0; j < AR[i].size(); j++)
        {
            count[(1 << C[AR[i][j]])]++;
            for (long long k = 0; k < K; k++)
            {
                if (k == C[AR[i][j]])
                    continue;
                count[((1 << C[AR[i][j]]) | (1 << k))] += voisins[AR[i][j]][k];
            }
        }
        for (long long j = 1; j < (1 << K); j++)
        {
            if (j & (1 << C[i]))
                continue;
            if (__builtin_popcount(j) > 2)
                continue;
            if (__builtin_popcount(j) == 1 && K >= 2)
                half += count[j];
            if (__builtin_popcount(j) == 1 && K >= 3)
            {
                for (long long k = 0; k < K; k++)
                {
                    if ((j & (1 << k)) || k == C[i])
                        continue;
                    half += count[(1 << k)] * count[j];
                }
            }
            if (__builtin_popcount(j) == 2 && K >= 4)
            {
                for (long long k = 0; k < K; k++)
                {
                    if ((j & (1 << k)) || k == C[i])
                        continue;
                    half += count[(1 << k)] * count[j];
                }
            }
            if (__builtin_popcount(j) == 2 && K >= 5)
            {
                half += count[j] * count[((1 << K) - j - (1 << C[i]))];
            }
        }
    }
    cout << tot * 2 + half;
}

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:29:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (long long j = 0; j < AR[i].size(); j++)
      |                               ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 416 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 9472 KB Output is correct
2 Correct 110 ms 8812 KB Output is correct
3 Correct 457 ms 39176 KB Output is correct
4 Correct 154 ms 13156 KB Output is correct
5 Correct 149 ms 13140 KB Output is correct
6 Correct 327 ms 28812 KB Output is correct
7 Correct 482 ms 39336 KB Output is correct
8 Correct 460 ms 39764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 416 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 432 KB Output is correct
11 Correct 119 ms 9472 KB Output is correct
12 Correct 110 ms 8812 KB Output is correct
13 Correct 457 ms 39176 KB Output is correct
14 Correct 154 ms 13156 KB Output is correct
15 Correct 149 ms 13140 KB Output is correct
16 Correct 327 ms 28812 KB Output is correct
17 Correct 482 ms 39336 KB Output is correct
18 Correct 460 ms 39764 KB Output is correct
19 Correct 119 ms 9556 KB Output is correct
20 Correct 118 ms 8868 KB Output is correct
21 Correct 438 ms 39272 KB Output is correct
22 Correct 172 ms 13152 KB Output is correct
23 Correct 151 ms 13108 KB Output is correct
24 Correct 366 ms 28624 KB Output is correct
25 Correct 437 ms 39084 KB Output is correct
26 Correct 477 ms 39764 KB Output is correct
27 Correct 96 ms 8788 KB Output is correct
28 Correct 130 ms 11448 KB Output is correct
29 Correct 473 ms 41480 KB Output is correct
30 Correct 294 ms 24260 KB Output is correct
31 Correct 322 ms 24628 KB Output is correct
32 Correct 509 ms 41300 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 33 ms 2656 KB Output isn't correct
3 Halted 0 ms 0 KB -