# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730936 |
2023-04-26T16:02:37 Z |
Karpin |
Paths (BOI18_paths) |
C++17 |
|
3000 ms |
482832 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];
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;
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);
onlyLines.push_back({a, b});
}
map<int, map<int, int>> amount;
amount[0] = {};
for(int j = 0; j < 1<<(k + 1); 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++){
vt<int> nums = {};
for(int j = 0; j < 1<<(k + 1); j++){
if (__builtin_popcount(j) == i) nums.push_back(j);
}
for (pair<int, int> line : onlyLines){
for(int j : nums){
if (!(j & colors[line.first]) || !(j & colors[line.second])) continue;
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
677 ms |
7048 KB |
Output is correct |
2 |
Correct |
449 ms |
4660 KB |
Output is correct |
3 |
Correct |
2540 ms |
257588 KB |
Output is correct |
4 |
Correct |
463 ms |
18152 KB |
Output is correct |
5 |
Correct |
70 ms |
12472 KB |
Output is correct |
6 |
Correct |
1849 ms |
173812 KB |
Output is correct |
7 |
Correct |
2519 ms |
258776 KB |
Output is correct |
8 |
Correct |
2523 ms |
258736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
677 ms |
7048 KB |
Output is correct |
12 |
Correct |
449 ms |
4660 KB |
Output is correct |
13 |
Correct |
2540 ms |
257588 KB |
Output is correct |
14 |
Correct |
463 ms |
18152 KB |
Output is correct |
15 |
Correct |
70 ms |
12472 KB |
Output is correct |
16 |
Correct |
1849 ms |
173812 KB |
Output is correct |
17 |
Correct |
2519 ms |
258776 KB |
Output is correct |
18 |
Correct |
2523 ms |
258736 KB |
Output is correct |
19 |
Correct |
643 ms |
8188 KB |
Output is correct |
20 |
Correct |
418 ms |
5776 KB |
Output is correct |
21 |
Correct |
2595 ms |
258744 KB |
Output is correct |
22 |
Correct |
488 ms |
18148 KB |
Output is correct |
23 |
Correct |
65 ms |
12496 KB |
Output is correct |
24 |
Correct |
1696 ms |
174056 KB |
Output is correct |
25 |
Correct |
2477 ms |
258736 KB |
Output is correct |
26 |
Correct |
2481 ms |
258688 KB |
Output is correct |
27 |
Correct |
963 ms |
5768 KB |
Output is correct |
28 |
Correct |
1649 ms |
16748 KB |
Output is correct |
29 |
Execution timed out |
3084 ms |
482832 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
614 ms |
2588 KB |
Output is correct |
3 |
Correct |
145 ms |
1504 KB |
Output is correct |
4 |
Correct |
667 ms |
86020 KB |
Output is correct |
5 |
Correct |
498 ms |
85952 KB |
Output is correct |
6 |
Correct |
2448 ms |
311464 KB |
Output is correct |
7 |
Correct |
295 ms |
2000 KB |
Output is correct |
8 |
Correct |
1260 ms |
161300 KB |
Output is correct |
9 |
Correct |
938 ms |
161536 KB |
Output is correct |
10 |
Correct |
978 ms |
161300 KB |
Output is correct |
11 |
Correct |
1548 ms |
156340 KB |
Output is correct |
12 |
Correct |
1460 ms |
234048 KB |
Output is correct |
13 |
Correct |
1491 ms |
156456 KB |
Output is correct |
14 |
Correct |
2441 ms |
311592 KB |
Output is correct |
15 |
Correct |
2328 ms |
311628 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
448 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
320 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |