Submission #968706

# Submission time Handle Problem Language Result Execution time Memory
968706 2024-04-23T22:19:16 Z raphaelp Paths (BOI18_paths) C++14
70 / 100
559 ms 45968 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)
            {
                tot += 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 2 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 10668 KB Output is correct
2 Correct 102 ms 9840 KB Output is correct
3 Correct 452 ms 41044 KB Output is correct
4 Correct 152 ms 14492 KB Output is correct
5 Correct 150 ms 14392 KB Output is correct
6 Correct 352 ms 30644 KB Output is correct
7 Correct 465 ms 41480 KB Output is correct
8 Correct 487 ms 41552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 348 KB Output is correct
11 Correct 121 ms 10668 KB Output is correct
12 Correct 102 ms 9840 KB Output is correct
13 Correct 452 ms 41044 KB Output is correct
14 Correct 152 ms 14492 KB Output is correct
15 Correct 150 ms 14392 KB Output is correct
16 Correct 352 ms 30644 KB Output is correct
17 Correct 465 ms 41480 KB Output is correct
18 Correct 487 ms 41552 KB Output is correct
19 Correct 128 ms 10608 KB Output is correct
20 Correct 98 ms 9856 KB Output is correct
21 Correct 471 ms 41040 KB Output is correct
22 Correct 158 ms 14420 KB Output is correct
23 Correct 160 ms 14420 KB Output is correct
24 Correct 361 ms 30652 KB Output is correct
25 Correct 504 ms 41176 KB Output is correct
26 Correct 472 ms 41812 KB Output is correct
27 Correct 104 ms 9812 KB Output is correct
28 Correct 147 ms 12452 KB Output is correct
29 Correct 518 ms 45756 KB Output is correct
30 Correct 365 ms 28304 KB Output is correct
31 Correct 352 ms 28300 KB Output is correct
32 Correct 559 ms 45968 KB Output is correct
33 Correct 1 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 1 ms 348 KB Output is correct
37 Correct 0 ms 436 KB Output is correct
38 Correct 0 ms 352 KB Output is correct
39 Correct 0 ms 436 KB Output is correct
40 Correct 0 ms 352 KB Output is correct
41 Correct 0 ms 436 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Incorrect 38 ms 3432 KB Output isn't correct
3 Halted 0 ms 0 KB -