답안 #1031658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031658 2024-07-23T03:20:27 Z SamuellH12 Bitaro’s Party (JOI18_bitaro) C++17
7 / 100
1583 ms 524288 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 = 300;
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][4*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 >= 3*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);
      |    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 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 8 ms 7908 KB Output is correct
6 Correct 7 ms 7772 KB Output is correct
7 Correct 7 ms 7772 KB Output is correct
8 Correct 12 ms 10588 KB Output is correct
9 Correct 12 ms 10588 KB Output is correct
10 Correct 12 ms 10768 KB Output is correct
11 Correct 14 ms 10332 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 15 ms 10284 KB Output is correct
14 Correct 12 ms 8808 KB Output is correct
15 Correct 8 ms 7768 KB Output is correct
16 Correct 12 ms 8760 KB Output is correct
17 Correct 13 ms 9308 KB Output is correct
18 Correct 9 ms 8048 KB Output is correct
19 Correct 14 ms 9544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 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 8 ms 7908 KB Output is correct
6 Correct 7 ms 7772 KB Output is correct
7 Correct 7 ms 7772 KB Output is correct
8 Correct 12 ms 10588 KB Output is correct
9 Correct 12 ms 10588 KB Output is correct
10 Correct 12 ms 10768 KB Output is correct
11 Correct 14 ms 10332 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 15 ms 10284 KB Output is correct
14 Correct 12 ms 8808 KB Output is correct
15 Correct 8 ms 7768 KB Output is correct
16 Correct 12 ms 8760 KB Output is correct
17 Correct 13 ms 9308 KB Output is correct
18 Correct 9 ms 8048 KB Output is correct
19 Correct 14 ms 9544 KB Output is correct
20 Correct 1583 ms 14776 KB Output is correct
21 Correct 1430 ms 15036 KB Output is correct
22 Correct 1496 ms 14928 KB Output is correct
23 Correct 1460 ms 14904 KB Output is correct
24 Runtime error 1194 ms 524288 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2648 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 8 ms 7908 KB Output is correct
6 Correct 7 ms 7772 KB Output is correct
7 Correct 7 ms 7772 KB Output is correct
8 Correct 12 ms 10588 KB Output is correct
9 Correct 12 ms 10588 KB Output is correct
10 Correct 12 ms 10768 KB Output is correct
11 Correct 14 ms 10332 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 15 ms 10284 KB Output is correct
14 Correct 12 ms 8808 KB Output is correct
15 Correct 8 ms 7768 KB Output is correct
16 Correct 12 ms 8760 KB Output is correct
17 Correct 13 ms 9308 KB Output is correct
18 Correct 9 ms 8048 KB Output is correct
19 Correct 14 ms 9544 KB Output is correct
20 Correct 1583 ms 14776 KB Output is correct
21 Correct 1430 ms 15036 KB Output is correct
22 Correct 1496 ms 14928 KB Output is correct
23 Correct 1460 ms 14904 KB Output is correct
24 Runtime error 1194 ms 524288 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -