답안 #730958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730958 2023-04-26T16:52:13 Z Karpin Paths (BOI18_paths) C++17
100 / 100
2945 ms 271956 KB
#include <bits/stdc++.h>

using namespace std;


#define ll long long
#define vt vector
#define ar array


void solve(){
		
    int n, m, k;
    cin >> n >> m >> k;

    int colors[n];

    map<pair<int, int>, vt<int>> remaining;

    for(int i = 0; i < n; i++){
        cin >> colors[i];
        colors[i]--;
        if (colors[i] == 0) colors[i] = 1;
        else if (colors[i] == 1) colors[i] = 2;
        else if (colors[i] == 2) colors[i] = 4;
        else if (colors[i] == 3) colors[i] = 8;
        else if (colors[i] == 4) colors[i] = 16;
    }

    // map<int, vt<int>> lines;

    vt<pair<int, int>> onlyLines;
    int myypow = pow(2, k) - 1;

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        // if (lines.find(a) == lines.end()) lines[a] = {};
        // if (lines.find(b) == lines.end()) lines[b] = {};

        // lines[a].push_back(b);
        // lines[b].push_back(a);
        if (colors[a] == colors[b]) continue;
        onlyLines.push_back({a, b});
        remaining[{a, b}] = {};
        for(int kkk = 1; kkk < myypow + 1; kkk *= 2){
            if (colors[a] == kkk || colors[b] == kkk) continue;
            remaining[{a, b}].push_back(kkk);
        }
    }

    vt<pair<int, int>> kra = {{0, 1}, {0, 2}, {1, 2}};


    map<int, map<int, int>> amount;

    amount[0] = {};

    for(int j = 1; j < 1<<k; j++){
        amount[0][j] = 0;
    }
    for(int i = 1; i < n; i++) amount[i] = amount[0];

    for(int i = 0; i < n; i++){
        amount[i][colors[i]] = 1;
    }

    ll res = 0;

    


    for(int i = 2; i <= k; i++){
        for (pair<int, int> line : onlyLines){
            
            int j = colors[line.first] + colors[line.second];
            if (i == 2){
                ll mykk = amount[line.second][j - colors[line.first]];
                amount[line.first][j] += mykk;
                res += mykk;
                mykk = amount[line.first][j - colors[line.second]];
                amount[line.second][j] += mykk;
                res += mykk;
            }
            else if (i == 3){
                for(int kl = 0; kl < k - 2; kl++){
                    j += remaining[line][kl];
                    ll mykk = amount[line.second][j - colors[line.first]];
                    amount[line.first][j] += mykk;
                    res += mykk;
                    mykk = amount[line.first][j - colors[line.second]];
                    amount[line.second][j] += mykk;
                    res += mykk;
                    j -= remaining[line][kl];
                }
            }
            if (i == 4 && k == 5){
                
                for(int kl = 0; kl < k - 2; kl++){
                    j += remaining[line][kra[kl].first];
                    j += remaining[line][kra[kl].second];
                    ll mykk = amount[line.second][j - colors[line.first]];
                    amount[line.first][j] += mykk;
                    res += mykk;
                    mykk = amount[line.first][j - colors[line.second]];
                    amount[line.second][j] += mykk;
                    res += mykk;
                    j -= remaining[line][kra[kl].first];
                    j -= remaining[line][kra[kl].second];
                }
            }
            if (i == 5 || (i == 4 && k == 4)){
                j = myypow;
                ll mykk = amount[line.second][j - colors[line.first]];
                amount[line.first][j] += mykk;
                res += mykk;
                mykk = amount[line.first][j - colors[line.second]];
                amount[line.second][j] += mykk;
                res += mykk;
            }
                

        }
    }

    cout << res << endl;


}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int testcases = 1;

	// cin >> testcases;

	while(testcases--){
		solve();
	}

	return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 651 ms 26220 KB Output is correct
2 Correct 470 ms 24484 KB Output is correct
3 Correct 1608 ms 152020 KB Output is correct
4 Correct 265 ms 20584 KB Output is correct
5 Correct 53 ms 4796 KB Output is correct
6 Correct 1229 ms 109420 KB Output is correct
7 Correct 1748 ms 152020 KB Output is correct
8 Correct 1693 ms 152044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 651 ms 26220 KB Output is correct
12 Correct 470 ms 24484 KB Output is correct
13 Correct 1608 ms 152020 KB Output is correct
14 Correct 265 ms 20584 KB Output is correct
15 Correct 53 ms 4796 KB Output is correct
16 Correct 1229 ms 109420 KB Output is correct
17 Correct 1748 ms 152020 KB Output is correct
18 Correct 1693 ms 152044 KB Output is correct
19 Correct 623 ms 26252 KB Output is correct
20 Correct 511 ms 24444 KB Output is correct
21 Correct 1546 ms 152016 KB Output is correct
22 Correct 273 ms 20636 KB Output is correct
23 Correct 70 ms 4892 KB Output is correct
24 Correct 1230 ms 109420 KB Output is correct
25 Correct 1542 ms 152028 KB Output is correct
26 Correct 1601 ms 152048 KB Output is correct
27 Correct 867 ms 27696 KB Output is correct
28 Correct 1047 ms 33424 KB Output is correct
29 Correct 2819 ms 267632 KB Output is correct
30 Correct 2212 ms 151176 KB Output is correct
31 Correct 2318 ms 153980 KB Output is correct
32 Correct 2945 ms 271956 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 496 ms 10692 KB Output is correct
3 Correct 122 ms 8764 KB Output is correct
4 Correct 415 ms 51060 KB Output is correct
5 Correct 326 ms 51064 KB Output is correct
6 Correct 1457 ms 165336 KB Output is correct
7 Correct 228 ms 9772 KB Output is correct
8 Correct 751 ms 89608 KB Output is correct
9 Correct 577 ms 89660 KB Output is correct
10 Correct 813 ms 92552 KB Output is correct
11 Correct 991 ms 86700 KB Output is correct
12 Correct 1204 ms 128848 KB Output is correct
13 Correct 1054 ms 88436 KB Output is correct
14 Correct 1353 ms 165328 KB Output is correct
15 Correct 1403 ms 165336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct