Submission #572039

# Submission time Handle Problem Language Result Execution time Memory
572039 2022-06-03T12:09:54 Z jjang36524 From Hacks to Snitches (BOI21_watchmen) C++14
35 / 100
3835 ms 141124 KB
#include <bits/stdc++.h>
using namespace std;
#define INF 998244353
int cylen[1000];
int cycno[300100];
int cypos[300100];
vector<int>link[300100];
vector<int>dp[300100];
vector<bool>vis[300100];
priority_queue<pair<int, pair<int, int>>>x;
void upd(pair<int, int> pos)
{
	int o = pos.second % cylen[cycno[pos.first]];
	if ((cylen[cycno[pos.first]] == 1 || o != cypos[pos.first]) && pos.second < dp[pos.first][o])
	{
		dp[pos.first][o] = pos.second;
		x.push({ {-pos.second},{pos.first,o} });
	}
}
int getne(int cur, int nem, int mb)
{
	return cur + (nem + mb - cur % mb) % mb;
}
int main()
{
	int N, M, K;
	cin >> N >> M;
	int i;
	for (i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		link[a].push_back(b);
		link[b].push_back(a);
	}
	cin >> K;
	cylen[0] = 1;
	for (i = 1; i <= K; i++)
	{
		cin >> cylen[i];
		int j;
		for (j = 0; j < cylen[i]; j++)
		{
			int a;
			cin >> a;
			cycno[a] = i;
			cypos[a] = j;
		}
	}
	for (i = 1; i <= N; i++)
	{
		if (!cycno[i])
		{
			dp[i].resize(1, INF);
		}
		else
		{
			dp[i].resize(cylen[cycno[i]], INF);
		}
		vis[i].resize(dp[i].size());
	}
	upd({ 1,0 });
	while (x.size())
	{
		auto cu = x.top();
		x.pop();
		int t = -cu.first;
		int curp = cu.second.first;
		int curr = cu.second.second;
		if (vis[curp][curr])
		{
			continue;
		}
		vis[curp][curr] = 1;
		for (i = 0; i < link[curp].size(); i++)
		{
			int nexp = link[curp][i];
			int pa = cycno[curp];
			int pb = cycno[nexp];
			if (!pa || pa != pb || (cypos[nexp] + 1) % cylen[pa] != cypos[curp] || cypos[nexp] != curr)
			{
				upd({ nexp,t + 1 });
			}
			if (!pa && pb)
			{
				upd({ nexp,t + 1 + (cypos[nexp] + cylen[pb] - t % cylen[pb]) % cylen[pb] });
			}
			int re = 0;
			if (pa && pb && (pa != pb || (cypos[curp] + 1) % cylen[pa] != cypos[nexp] && (cypos[nexp] + 1) % cylen[pb] != cypos[curp]))
			{
				int jw = getne(t, cypos[nexp], cylen[pb]);
				int jjw = getne(jw, cypos[curp], cylen[pa]);
				if (jw != jjw)
				{
					upd({ nexp,jw + 1 });
					re = 1;
				}
				else
				{
					int bo = getne(cypos[curp], curr, cylen[pa]) -cypos[curp]+jw;
					upd({ nexp,bo + 1 });
					if (cylen[pb] % cylen[pa] && (cylen[pa] % cylen[pb] || (cypos[curp] + cylen[pa] - curr) % cylen[pa] >= cylen[pb]))
					{
						upd({ nexp,bo + 1 + (cypos[pb] + cylen[pb] - bo % cylen[pb] % cylen[pb]) });
					}
				}
			}
			if (!pa || !pb || re)
			{
				swap(link[curp][i], link[curp].back());
				link[curp].pop_back();
				i--;
			}
		}
		upd({ curp, t + 1 });
	}
	if (dp[N][0] == 998244353)
	{
		cout << "impossible";
	}
	else
	{
		cout << dp[N][0];
	}
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for (i = 0; i < link[curp].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~~~~
watchmen.cpp:89:78: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   89 |    if (pa && pb && (pa != pb || (cypos[curp] + 1) % cylen[pa] != cypos[nexp] && (cypos[nexp] + 1) % cylen[pb] != cypos[curp]))
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 27560 KB Output is correct
2 Correct 148 ms 37224 KB Output is correct
3 Correct 140 ms 36468 KB Output is correct
4 Correct 140 ms 36652 KB Output is correct
5 Correct 19 ms 26240 KB Output is correct
6 Correct 148 ms 36504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 27596 KB Output is correct
2 Correct 133 ms 37248 KB Output is correct
3 Correct 149 ms 36568 KB Output is correct
4 Correct 151 ms 36536 KB Output is correct
5 Correct 16 ms 26196 KB Output is correct
6 Correct 127 ms 36380 KB Output is correct
7 Correct 129 ms 36416 KB Output is correct
8 Correct 153 ms 36448 KB Output is correct
9 Correct 133 ms 36372 KB Output is correct
10 Correct 125 ms 36560 KB Output is correct
11 Correct 130 ms 36548 KB Output is correct
12 Correct 125 ms 36344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 27596 KB Output is correct
2 Correct 133 ms 37248 KB Output is correct
3 Correct 149 ms 36568 KB Output is correct
4 Correct 151 ms 36536 KB Output is correct
5 Correct 16 ms 26196 KB Output is correct
6 Correct 127 ms 36380 KB Output is correct
7 Correct 129 ms 36416 KB Output is correct
8 Correct 153 ms 36448 KB Output is correct
9 Correct 133 ms 36372 KB Output is correct
10 Correct 125 ms 36560 KB Output is correct
11 Correct 130 ms 36548 KB Output is correct
12 Correct 125 ms 36344 KB Output is correct
13 Correct 58 ms 27684 KB Output is correct
14 Correct 138 ms 37180 KB Output is correct
15 Correct 130 ms 36508 KB Output is correct
16 Correct 154 ms 36632 KB Output is correct
17 Correct 16 ms 26212 KB Output is correct
18 Correct 134 ms 36428 KB Output is correct
19 Correct 121 ms 36388 KB Output is correct
20 Correct 127 ms 36440 KB Output is correct
21 Correct 143 ms 36428 KB Output is correct
22 Correct 130 ms 36712 KB Output is correct
23 Correct 130 ms 36548 KB Output is correct
24 Correct 134 ms 36456 KB Output is correct
25 Correct 2953 ms 121528 KB Output is correct
26 Correct 2859 ms 126056 KB Output is correct
27 Correct 2645 ms 121744 KB Output is correct
28 Correct 2395 ms 125732 KB Output is correct
29 Correct 2796 ms 117336 KB Output is correct
30 Correct 2718 ms 119640 KB Output is correct
31 Correct 2980 ms 125896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 27596 KB Output is correct
2 Correct 133 ms 37248 KB Output is correct
3 Correct 149 ms 36568 KB Output is correct
4 Correct 151 ms 36536 KB Output is correct
5 Correct 16 ms 26196 KB Output is correct
6 Correct 127 ms 36380 KB Output is correct
7 Correct 129 ms 36416 KB Output is correct
8 Correct 153 ms 36448 KB Output is correct
9 Correct 133 ms 36372 KB Output is correct
10 Correct 125 ms 36560 KB Output is correct
11 Correct 130 ms 36548 KB Output is correct
12 Correct 125 ms 36344 KB Output is correct
13 Correct 58 ms 27684 KB Output is correct
14 Correct 138 ms 37180 KB Output is correct
15 Correct 130 ms 36508 KB Output is correct
16 Correct 154 ms 36632 KB Output is correct
17 Correct 16 ms 26212 KB Output is correct
18 Correct 134 ms 36428 KB Output is correct
19 Correct 121 ms 36388 KB Output is correct
20 Correct 127 ms 36440 KB Output is correct
21 Correct 143 ms 36428 KB Output is correct
22 Correct 130 ms 36712 KB Output is correct
23 Correct 130 ms 36548 KB Output is correct
24 Correct 134 ms 36456 KB Output is correct
25 Correct 2953 ms 121528 KB Output is correct
26 Correct 2859 ms 126056 KB Output is correct
27 Correct 2645 ms 121744 KB Output is correct
28 Correct 2395 ms 125732 KB Output is correct
29 Correct 2796 ms 117336 KB Output is correct
30 Correct 2718 ms 119640 KB Output is correct
31 Correct 2980 ms 125896 KB Output is correct
32 Correct 49 ms 27620 KB Output is correct
33 Correct 138 ms 37252 KB Output is correct
34 Correct 127 ms 36452 KB Output is correct
35 Correct 131 ms 36616 KB Output is correct
36 Correct 16 ms 26196 KB Output is correct
37 Correct 127 ms 36504 KB Output is correct
38 Correct 123 ms 36432 KB Output is correct
39 Correct 123 ms 36344 KB Output is correct
40 Correct 124 ms 36348 KB Output is correct
41 Correct 125 ms 36552 KB Output is correct
42 Correct 125 ms 36448 KB Output is correct
43 Correct 125 ms 36404 KB Output is correct
44 Correct 2821 ms 121440 KB Output is correct
45 Correct 2660 ms 126076 KB Output is correct
46 Correct 2516 ms 121716 KB Output is correct
47 Correct 2193 ms 125688 KB Output is correct
48 Correct 2612 ms 117172 KB Output is correct
49 Correct 2606 ms 119312 KB Output is correct
50 Correct 2948 ms 125488 KB Output is correct
51 Correct 3518 ms 130548 KB Output is correct
52 Correct 3835 ms 141124 KB Output is correct
53 Correct 3357 ms 131384 KB Output is correct
54 Correct 2261 ms 117280 KB Output is correct
55 Correct 3397 ms 131556 KB Output is correct
56 Correct 3259 ms 123720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 27560 KB Output is correct
2 Correct 148 ms 37224 KB Output is correct
3 Correct 140 ms 36468 KB Output is correct
4 Correct 140 ms 36652 KB Output is correct
5 Correct 19 ms 26240 KB Output is correct
6 Correct 148 ms 36504 KB Output is correct
7 Correct 50 ms 27596 KB Output is correct
8 Correct 133 ms 37248 KB Output is correct
9 Correct 149 ms 36568 KB Output is correct
10 Correct 151 ms 36536 KB Output is correct
11 Correct 16 ms 26196 KB Output is correct
12 Correct 127 ms 36380 KB Output is correct
13 Correct 129 ms 36416 KB Output is correct
14 Correct 153 ms 36448 KB Output is correct
15 Correct 133 ms 36372 KB Output is correct
16 Correct 125 ms 36560 KB Output is correct
17 Correct 130 ms 36548 KB Output is correct
18 Correct 125 ms 36344 KB Output is correct
19 Correct 14 ms 26104 KB Output is correct
20 Correct 15 ms 26068 KB Output is correct
21 Correct 15 ms 26152 KB Output is correct
22 Correct 51 ms 27560 KB Output is correct
23 Correct 136 ms 37196 KB Output is correct
24 Correct 134 ms 36484 KB Output is correct
25 Correct 132 ms 36616 KB Output is correct
26 Correct 17 ms 26144 KB Output is correct
27 Correct 129 ms 36504 KB Output is correct
28 Correct 125 ms 36380 KB Output is correct
29 Correct 123 ms 36408 KB Output is correct
30 Correct 129 ms 36488 KB Output is correct
31 Correct 135 ms 36648 KB Output is correct
32 Correct 132 ms 36584 KB Output is correct
33 Correct 130 ms 36436 KB Output is correct
34 Correct 2867 ms 121464 KB Output is correct
35 Correct 2996 ms 118032 KB Output is correct
36 Correct 2987 ms 117728 KB Output is correct
37 Correct 2688 ms 123128 KB Output is correct
38 Correct 2885 ms 120400 KB Output is correct
39 Correct 2628 ms 117052 KB Output is correct
40 Correct 2616 ms 117124 KB Output is correct
41 Correct 2640 ms 116580 KB Output is correct
42 Correct 2859 ms 119748 KB Output is correct
43 Correct 2937 ms 123356 KB Output is correct
44 Correct 3105 ms 123340 KB Output is correct
45 Incorrect 2627 ms 117796 KB Output isn't correct
46 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 27560 KB Output is correct
2 Correct 148 ms 37224 KB Output is correct
3 Correct 140 ms 36468 KB Output is correct
4 Correct 140 ms 36652 KB Output is correct
5 Correct 19 ms 26240 KB Output is correct
6 Correct 148 ms 36504 KB Output is correct
7 Correct 50 ms 27596 KB Output is correct
8 Correct 133 ms 37248 KB Output is correct
9 Correct 149 ms 36568 KB Output is correct
10 Correct 151 ms 36536 KB Output is correct
11 Correct 16 ms 26196 KB Output is correct
12 Correct 127 ms 36380 KB Output is correct
13 Correct 129 ms 36416 KB Output is correct
14 Correct 153 ms 36448 KB Output is correct
15 Correct 133 ms 36372 KB Output is correct
16 Correct 125 ms 36560 KB Output is correct
17 Correct 130 ms 36548 KB Output is correct
18 Correct 125 ms 36344 KB Output is correct
19 Correct 58 ms 27684 KB Output is correct
20 Correct 138 ms 37180 KB Output is correct
21 Correct 130 ms 36508 KB Output is correct
22 Correct 154 ms 36632 KB Output is correct
23 Correct 16 ms 26212 KB Output is correct
24 Correct 134 ms 36428 KB Output is correct
25 Correct 121 ms 36388 KB Output is correct
26 Correct 127 ms 36440 KB Output is correct
27 Correct 143 ms 36428 KB Output is correct
28 Correct 130 ms 36712 KB Output is correct
29 Correct 130 ms 36548 KB Output is correct
30 Correct 134 ms 36456 KB Output is correct
31 Correct 2953 ms 121528 KB Output is correct
32 Correct 2859 ms 126056 KB Output is correct
33 Correct 2645 ms 121744 KB Output is correct
34 Correct 2395 ms 125732 KB Output is correct
35 Correct 2796 ms 117336 KB Output is correct
36 Correct 2718 ms 119640 KB Output is correct
37 Correct 2980 ms 125896 KB Output is correct
38 Correct 14 ms 26104 KB Output is correct
39 Correct 15 ms 26068 KB Output is correct
40 Correct 15 ms 26152 KB Output is correct
41 Correct 51 ms 27560 KB Output is correct
42 Correct 136 ms 37196 KB Output is correct
43 Correct 134 ms 36484 KB Output is correct
44 Correct 132 ms 36616 KB Output is correct
45 Correct 17 ms 26144 KB Output is correct
46 Correct 129 ms 36504 KB Output is correct
47 Correct 125 ms 36380 KB Output is correct
48 Correct 123 ms 36408 KB Output is correct
49 Correct 129 ms 36488 KB Output is correct
50 Correct 135 ms 36648 KB Output is correct
51 Correct 132 ms 36584 KB Output is correct
52 Correct 130 ms 36436 KB Output is correct
53 Correct 2867 ms 121464 KB Output is correct
54 Correct 2996 ms 118032 KB Output is correct
55 Correct 2987 ms 117728 KB Output is correct
56 Correct 2688 ms 123128 KB Output is correct
57 Correct 2885 ms 120400 KB Output is correct
58 Correct 2628 ms 117052 KB Output is correct
59 Correct 2616 ms 117124 KB Output is correct
60 Correct 2640 ms 116580 KB Output is correct
61 Correct 2859 ms 119748 KB Output is correct
62 Correct 2937 ms 123356 KB Output is correct
63 Correct 3105 ms 123340 KB Output is correct
64 Incorrect 2627 ms 117796 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 27560 KB Output is correct
2 Correct 148 ms 37224 KB Output is correct
3 Correct 140 ms 36468 KB Output is correct
4 Correct 140 ms 36652 KB Output is correct
5 Correct 19 ms 26240 KB Output is correct
6 Correct 148 ms 36504 KB Output is correct
7 Correct 50 ms 27596 KB Output is correct
8 Correct 133 ms 37248 KB Output is correct
9 Correct 149 ms 36568 KB Output is correct
10 Correct 151 ms 36536 KB Output is correct
11 Correct 16 ms 26196 KB Output is correct
12 Correct 127 ms 36380 KB Output is correct
13 Correct 129 ms 36416 KB Output is correct
14 Correct 153 ms 36448 KB Output is correct
15 Correct 133 ms 36372 KB Output is correct
16 Correct 125 ms 36560 KB Output is correct
17 Correct 130 ms 36548 KB Output is correct
18 Correct 125 ms 36344 KB Output is correct
19 Correct 58 ms 27684 KB Output is correct
20 Correct 138 ms 37180 KB Output is correct
21 Correct 130 ms 36508 KB Output is correct
22 Correct 154 ms 36632 KB Output is correct
23 Correct 16 ms 26212 KB Output is correct
24 Correct 134 ms 36428 KB Output is correct
25 Correct 121 ms 36388 KB Output is correct
26 Correct 127 ms 36440 KB Output is correct
27 Correct 143 ms 36428 KB Output is correct
28 Correct 130 ms 36712 KB Output is correct
29 Correct 130 ms 36548 KB Output is correct
30 Correct 134 ms 36456 KB Output is correct
31 Correct 2953 ms 121528 KB Output is correct
32 Correct 2859 ms 126056 KB Output is correct
33 Correct 2645 ms 121744 KB Output is correct
34 Correct 2395 ms 125732 KB Output is correct
35 Correct 2796 ms 117336 KB Output is correct
36 Correct 2718 ms 119640 KB Output is correct
37 Correct 2980 ms 125896 KB Output is correct
38 Correct 49 ms 27620 KB Output is correct
39 Correct 138 ms 37252 KB Output is correct
40 Correct 127 ms 36452 KB Output is correct
41 Correct 131 ms 36616 KB Output is correct
42 Correct 16 ms 26196 KB Output is correct
43 Correct 127 ms 36504 KB Output is correct
44 Correct 123 ms 36432 KB Output is correct
45 Correct 123 ms 36344 KB Output is correct
46 Correct 124 ms 36348 KB Output is correct
47 Correct 125 ms 36552 KB Output is correct
48 Correct 125 ms 36448 KB Output is correct
49 Correct 125 ms 36404 KB Output is correct
50 Correct 2821 ms 121440 KB Output is correct
51 Correct 2660 ms 126076 KB Output is correct
52 Correct 2516 ms 121716 KB Output is correct
53 Correct 2193 ms 125688 KB Output is correct
54 Correct 2612 ms 117172 KB Output is correct
55 Correct 2606 ms 119312 KB Output is correct
56 Correct 2948 ms 125488 KB Output is correct
57 Correct 3518 ms 130548 KB Output is correct
58 Correct 3835 ms 141124 KB Output is correct
59 Correct 3357 ms 131384 KB Output is correct
60 Correct 2261 ms 117280 KB Output is correct
61 Correct 3397 ms 131556 KB Output is correct
62 Correct 3259 ms 123720 KB Output is correct
63 Correct 14 ms 26104 KB Output is correct
64 Correct 15 ms 26068 KB Output is correct
65 Correct 15 ms 26152 KB Output is correct
66 Correct 51 ms 27560 KB Output is correct
67 Correct 136 ms 37196 KB Output is correct
68 Correct 134 ms 36484 KB Output is correct
69 Correct 132 ms 36616 KB Output is correct
70 Correct 17 ms 26144 KB Output is correct
71 Correct 129 ms 36504 KB Output is correct
72 Correct 125 ms 36380 KB Output is correct
73 Correct 123 ms 36408 KB Output is correct
74 Correct 129 ms 36488 KB Output is correct
75 Correct 135 ms 36648 KB Output is correct
76 Correct 132 ms 36584 KB Output is correct
77 Correct 130 ms 36436 KB Output is correct
78 Correct 2867 ms 121464 KB Output is correct
79 Correct 2996 ms 118032 KB Output is correct
80 Correct 2987 ms 117728 KB Output is correct
81 Correct 2688 ms 123128 KB Output is correct
82 Correct 2885 ms 120400 KB Output is correct
83 Correct 2628 ms 117052 KB Output is correct
84 Correct 2616 ms 117124 KB Output is correct
85 Correct 2640 ms 116580 KB Output is correct
86 Correct 2859 ms 119748 KB Output is correct
87 Correct 2937 ms 123356 KB Output is correct
88 Correct 3105 ms 123340 KB Output is correct
89 Incorrect 2627 ms 117796 KB Output isn't correct
90 Halted 0 ms 0 KB -