Submission #1031620

# Submission time Handle Problem Language Result Execution time Memory
1031620 2024-07-23T02:45:31 Z SamuellH12 Bitaro’s Party (JOI18_bitaro) C++17
7 / 100
2000 ms 15680 KB
#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
#define pii pair<int,int>
const int MAXN = 1e5 + 1;
const int SQRT = 316;
using namespace std;

int block[MAXN], dp[MAXN], order[MAXN], tempo;
vector<int> trafo[MAXN];
vector<pii> best[MAXN];
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].push_back(pii(0, u));
		for(auto v : trafo[u]){
			for(auto [x, w] : best[v])
				best[u].push_back(pii(x-1, w));
			
				sort(ALL(best[u]));
				best[u].resize(min(SQRT, (int)(unique(ALL(best[u])) - best[u].begin())));
		}
 
		sort(ALL(best[u]));
		best[u].resize(min(SQRT, (int)(unique(ALL(best[u])) - best[u].begin())));
	}
 
	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(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:45:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   45 |    for(auto [x, w] : best[v])
      |    ^~~
bitaro.cpp:48:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   48 |     sort(ALL(best[u]));
      |     ^~~~
bitaro.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d %d", &t, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:64:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 12 ms 6748 KB Output is correct
6 Correct 10 ms 6492 KB Output is correct
7 Correct 10 ms 6440 KB Output is correct
8 Correct 23 ms 11316 KB Output is correct
9 Correct 23 ms 11356 KB Output is correct
10 Correct 22 ms 11356 KB Output is correct
11 Correct 24 ms 10844 KB Output is correct
12 Correct 16 ms 8028 KB Output is correct
13 Correct 23 ms 10792 KB Output is correct
14 Correct 17 ms 8024 KB Output is correct
15 Correct 15 ms 6492 KB Output is correct
16 Correct 17 ms 8028 KB Output is correct
17 Correct 19 ms 9264 KB Output is correct
18 Correct 15 ms 7260 KB Output is correct
19 Correct 25 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 12 ms 6748 KB Output is correct
6 Correct 10 ms 6492 KB Output is correct
7 Correct 10 ms 6440 KB Output is correct
8 Correct 23 ms 11316 KB Output is correct
9 Correct 23 ms 11356 KB Output is correct
10 Correct 22 ms 11356 KB Output is correct
11 Correct 24 ms 10844 KB Output is correct
12 Correct 16 ms 8028 KB Output is correct
13 Correct 23 ms 10792 KB Output is correct
14 Correct 17 ms 8024 KB Output is correct
15 Correct 15 ms 6492 KB Output is correct
16 Correct 17 ms 8028 KB Output is correct
17 Correct 19 ms 9264 KB Output is correct
18 Correct 15 ms 7260 KB Output is correct
19 Correct 25 ms 9464 KB Output is correct
20 Execution timed out 2001 ms 15680 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 12 ms 6748 KB Output is correct
6 Correct 10 ms 6492 KB Output is correct
7 Correct 10 ms 6440 KB Output is correct
8 Correct 23 ms 11316 KB Output is correct
9 Correct 23 ms 11356 KB Output is correct
10 Correct 22 ms 11356 KB Output is correct
11 Correct 24 ms 10844 KB Output is correct
12 Correct 16 ms 8028 KB Output is correct
13 Correct 23 ms 10792 KB Output is correct
14 Correct 17 ms 8024 KB Output is correct
15 Correct 15 ms 6492 KB Output is correct
16 Correct 17 ms 8028 KB Output is correct
17 Correct 19 ms 9264 KB Output is correct
18 Correct 15 ms 7260 KB Output is correct
19 Correct 25 ms 9464 KB Output is correct
20 Execution timed out 2001 ms 15680 KB Time limit exceeded
21 Halted 0 ms 0 KB -