Submission #1031654

# Submission time Handle Problem Language Result Execution time Memory
1031654 2024-07-23T03:16:55 Z SamuellH12 Bitaro’s Party (JOI18_bitaro) C++17
14 / 100
2000 ms 156132 KB
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
#define pii pair<int,int>
const int MAXN = 1e5 + 64;
const int SQRT = 30;
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")

int block[MAXN], dp[MAXN], order[MAXN], tempo;
vector<int> trafo[MAXN];
pii best[MAXN][6*SQRT+5];
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int main(){
	ios::sync_with_stdio(false);
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	
	for(int i=0, u, v; i<m; i++)
	{
		scanf("%d %d", &u, &v);
		trafo[v].push_back(u);
		dp[u]++;
	}

	deque<int> fila;
	for(int i=1; i<=n; i++) if(!dp[i]) fila.push_back(i);
	int od = n;
	while(!fila.empty())
	{
		int u = fila.front(); fila.pop_front();
		order[--od] = u;
		// shuffle(ALL(trafo[u]), rng);
 
		for(int v : trafo[u])
			if(--dp[v] == 0)
				fila.push_back(v);
	}
	order[n] = -1;

	for(int u : order)
	{
		if(u == -1) break;
        best[u][0] = pii(0, u);
		int sz = 1;
		for(auto v : trafo[u]){
			for(auto [x, w] : best[v])
			{
				if(w == -1) break;
				best[u][sz++] = pii(x-1, w);
			}
			
			if(sz >= 5*SQRT)
			{
				sort(best[u], best[u]+sz);
				sz = min(SQRT, (int)(unique(best[u], best[u]+sz) - best[u]));
			}
		}
 
		sort(best[u], best[u]+sz);
		sz = min(SQRT, (int)(unique(best[u], best[u]+sz) - best[u]));
		best[u][sz] = pii(999999, -1);
	}
 
	int t, y;
	while(q--)
	{
		tempo++;
		scanf("%d %d", &t, &y);
 
		for(int i=0, x; i<y; i++)
		{
			scanf("%d", &x);
			block[x] = tempo;
		}
 
		int ans = -1;
 
		for(auto [x, w] : best[t]) 
		{
			if(w == -1) break;
			if(block[w] != tempo)
			{
				ans = -x;
				break;
			}
		}
 
		if(ans == -1) for(int u : order)
		{
			dp[u] = (block[u] == tempo ? -1 : 0);
	
			for(auto v : trafo[u])
				if(~dp[v]) 
					dp[u] = max(dp[u], dp[v]+1);
	
			if(u == t){ ans = dp[u]; break; }
		}
		
		printf("%d\n", ans);
	}
 
	return 0;	
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d %d", &t, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 3 ms 4120 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 3 ms 4120 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 125 ms 6992 KB Output is correct
21 Correct 106 ms 7248 KB Output is correct
22 Correct 123 ms 6992 KB Output is correct
23 Correct 116 ms 6868 KB Output is correct
24 Correct 220 ms 154020 KB Output is correct
25 Correct 228 ms 154080 KB Output is correct
26 Correct 228 ms 153812 KB Output is correct
27 Correct 140 ms 154452 KB Output is correct
28 Correct 149 ms 154552 KB Output is correct
29 Correct 140 ms 154192 KB Output is correct
30 Correct 175 ms 154412 KB Output is correct
31 Correct 194 ms 154528 KB Output is correct
32 Correct 161 ms 154196 KB Output is correct
33 Correct 164 ms 153936 KB Output is correct
34 Correct 188 ms 153940 KB Output is correct
35 Correct 158 ms 153804 KB Output is correct
36 Correct 180 ms 153936 KB Output is correct
37 Correct 185 ms 153940 KB Output is correct
38 Correct 158 ms 153724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 3 ms 4120 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 3 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 3 ms 4188 KB Output is correct
15 Correct 3 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 125 ms 6992 KB Output is correct
21 Correct 106 ms 7248 KB Output is correct
22 Correct 123 ms 6992 KB Output is correct
23 Correct 116 ms 6868 KB Output is correct
24 Correct 220 ms 154020 KB Output is correct
25 Correct 228 ms 154080 KB Output is correct
26 Correct 228 ms 153812 KB Output is correct
27 Correct 140 ms 154452 KB Output is correct
28 Correct 149 ms 154552 KB Output is correct
29 Correct 140 ms 154192 KB Output is correct
30 Correct 175 ms 154412 KB Output is correct
31 Correct 194 ms 154528 KB Output is correct
32 Correct 161 ms 154196 KB Output is correct
33 Correct 164 ms 153936 KB Output is correct
34 Correct 188 ms 153940 KB Output is correct
35 Correct 158 ms 153804 KB Output is correct
36 Correct 180 ms 153936 KB Output is correct
37 Correct 185 ms 153940 KB Output is correct
38 Correct 158 ms 153724 KB Output is correct
39 Correct 250 ms 155472 KB Output is correct
40 Correct 222 ms 154564 KB Output is correct
41 Correct 220 ms 154504 KB Output is correct
42 Correct 238 ms 154452 KB Output is correct
43 Correct 223 ms 154448 KB Output is correct
44 Correct 143 ms 8284 KB Output is correct
45 Correct 127 ms 7480 KB Output is correct
46 Correct 137 ms 7456 KB Output is correct
47 Correct 123 ms 6992 KB Output is correct
48 Correct 120 ms 7012 KB Output is correct
49 Correct 174 ms 155232 KB Output is correct
50 Correct 702 ms 154004 KB Output is correct
51 Correct 148 ms 8020 KB Output is correct
52 Correct 376 ms 7304 KB Output is correct
53 Correct 180 ms 154804 KB Output is correct
54 Correct 208 ms 154844 KB Output is correct
55 Correct 692 ms 153680 KB Output is correct
56 Correct 892 ms 153684 KB Output is correct
57 Correct 144 ms 8020 KB Output is correct
58 Correct 151 ms 8020 KB Output is correct
59 Correct 409 ms 7248 KB Output is correct
60 Correct 416 ms 7248 KB Output is correct
61 Correct 230 ms 154192 KB Output is correct
62 Correct 221 ms 153620 KB Output is correct
63 Correct 256 ms 153756 KB Output is correct
64 Correct 323 ms 154192 KB Output is correct
65 Correct 327 ms 153700 KB Output is correct
66 Correct 354 ms 153680 KB Output is correct
67 Correct 429 ms 154192 KB Output is correct
68 Correct 424 ms 153772 KB Output is correct
69 Correct 520 ms 153680 KB Output is correct
70 Correct 147 ms 154196 KB Output is correct
71 Correct 174 ms 153940 KB Output is correct
72 Correct 186 ms 153760 KB Output is correct
73 Correct 167 ms 154288 KB Output is correct
74 Correct 181 ms 153888 KB Output is correct
75 Correct 224 ms 153936 KB Output is correct
76 Correct 166 ms 155984 KB Output is correct
77 Correct 143 ms 154708 KB Output is correct
78 Correct 142 ms 154772 KB Output is correct
79 Correct 134 ms 8272 KB Output is correct
80 Correct 118 ms 7356 KB Output is correct
81 Correct 120 ms 6932 KB Output is correct
82 Correct 184 ms 156132 KB Output is correct
83 Correct 231 ms 155984 KB Output is correct
84 Correct 157 ms 154704 KB Output is correct
85 Correct 206 ms 154940 KB Output is correct
86 Correct 163 ms 154732 KB Output is correct
87 Correct 181 ms 154692 KB Output is correct
88 Correct 145 ms 8144 KB Output is correct
89 Correct 145 ms 8184 KB Output is correct
90 Correct 119 ms 7280 KB Output is correct
91 Correct 121 ms 7308 KB Output is correct
92 Correct 118 ms 6992 KB Output is correct
93 Correct 121 ms 7016 KB Output is correct
94 Correct 181 ms 155500 KB Output is correct
95 Correct 212 ms 155292 KB Output is correct
96 Correct 151 ms 154192 KB Output is correct
97 Correct 181 ms 154192 KB Output is correct
98 Correct 159 ms 154512 KB Output is correct
99 Correct 184 ms 154192 KB Output is correct
100 Correct 133 ms 8324 KB Output is correct
101 Correct 136 ms 8272 KB Output is correct
102 Correct 124 ms 7392 KB Output is correct
103 Correct 127 ms 7388 KB Output is correct
104 Correct 115 ms 6996 KB Output is correct
105 Correct 115 ms 6988 KB Output is correct
106 Correct 188 ms 155404 KB Output is correct
107 Correct 212 ms 155472 KB Output is correct
108 Correct 153 ms 154448 KB Output is correct
109 Correct 180 ms 154192 KB Output is correct
110 Correct 150 ms 154212 KB Output is correct
111 Correct 187 ms 154276 KB Output is correct
112 Correct 150 ms 8276 KB Output is correct
113 Correct 139 ms 8272 KB Output is correct
114 Correct 122 ms 7212 KB Output is correct
115 Correct 126 ms 7312 KB Output is correct
116 Correct 119 ms 6996 KB Output is correct
117 Correct 120 ms 6992 KB Output is correct
118 Execution timed out 2082 ms 154176 KB Time limit exceeded
119 Halted 0 ms 0 KB -