답안 #498683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498683 2021-12-26T06:43:19 Z LittleCube Paths (BOI18_paths) C++14
70 / 100
294 ms 21760 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

ll N, M, K, color[300005], adj[300005][6], adj2[100005][33];
pii edge[300005];
ll ans;

int encode(int i)
{
    return (1 << (i - 1));
}

signed main()
{
    //ios::sync_with_stdio(0), cin.tie(0);
    cin >> N >> M >> K;
    for (int i = 1; i <= N; i++)
        cin >> color[i];
    for (int i = 1; i <= M; i++)
        cin >> edge[i].F >> edge[i].S;
    if (K >= 2)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
                ans += 2;
    }
    cerr << ans << '\n';
    if (K >= 3)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
            {
                adj[edge[i].F][color[edge[i].S]]++;
                adj[edge[i].S][color[edge[i].F]]++;
            }
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= K; j++)
                for (int k = j + 1; k <= K; k++)
                    ans += adj[i][j] * adj[i][k] * 2;
    }
    cerr << ans << '\n';
    if (K >= 4)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
                for (int j = 1; j <= K; j++)
                    for (int k = 1; k <= K; k++)
                        if (j != k && color[edge[i].F] != k && color[edge[i].S] != j)
                            ans += adj[edge[i].F][j] * adj[edge[i].S][k] * 2;
    }
    cerr << ans << '\n';
    if (K >= 5)
    {
        for (int i = 1; i <= M; i++)
            if (color[edge[i].F] != color[edge[i].S])
            {
                for (int j = 1; j <= K; j++)
                    if (color[edge[i].F] != j)
                        adj2[edge[i].F][encode(color[edge[i].F]) ^ encode(color[edge[i].S]) ^ encode(j)] += adj[edge[i].S][j];
                for (int j = 1; j <= K; j++)
                    if (color[edge[i].S] != j)
                        adj2[edge[i].S][encode(color[edge[i].F]) ^ encode(color[edge[i].S]) ^ encode(j)] += adj[edge[i].F][j];
            }
        for (int i = 1; i <= N; i++)
            for (int j = 1; j <= K; j++)
                if (j != color[i])
                    for (int k = j + 1; k <= K; k++)
                        if (k != color[i] && k != j)
                            ans += adj2[i][encode(color[i]) ^ j ^ k] * adj2[i][31 ^ j ^ k] * 2;
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 5476 KB Output is correct
2 Correct 135 ms 4672 KB Output is correct
3 Correct 282 ms 21760 KB Output is correct
4 Correct 156 ms 5560 KB Output is correct
5 Correct 192 ms 5588 KB Output is correct
6 Correct 217 ms 16296 KB Output is correct
7 Correct 215 ms 20136 KB Output is correct
8 Correct 233 ms 20228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 206 ms 5476 KB Output is correct
12 Correct 135 ms 4672 KB Output is correct
13 Correct 282 ms 21760 KB Output is correct
14 Correct 156 ms 5560 KB Output is correct
15 Correct 192 ms 5588 KB Output is correct
16 Correct 217 ms 16296 KB Output is correct
17 Correct 215 ms 20136 KB Output is correct
18 Correct 233 ms 20228 KB Output is correct
19 Correct 145 ms 4124 KB Output is correct
20 Correct 123 ms 3928 KB Output is correct
21 Correct 258 ms 20160 KB Output is correct
22 Correct 151 ms 4052 KB Output is correct
23 Correct 174 ms 4080 KB Output is correct
24 Correct 201 ms 14932 KB Output is correct
25 Correct 237 ms 20216 KB Output is correct
26 Correct 228 ms 20212 KB Output is correct
27 Correct 137 ms 3880 KB Output is correct
28 Correct 183 ms 4376 KB Output is correct
29 Correct 294 ms 20180 KB Output is correct
30 Correct 221 ms 12172 KB Output is correct
31 Correct 231 ms 12040 KB Output is correct
32 Correct 268 ms 20244 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 65 ms 1860 KB Output isn't correct
3 Halted 0 ms 0 KB -