Submission #718998

# Submission time Handle Problem Language Result Execution time Memory
718998 2023-04-05T08:20:18 Z vinnipuh01 Event Hopping (BOI22_events) C++17
10 / 100
1500 ms 41280 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define sqrt sqrtl
 
using namespace std;
 
const long long oo = 1e9;
 
int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
 
    freopen ( "sum.in", "r", stdin )
*/

int n, m, x, y, a[ 100001 ], b[ 100001 ], d[ 100001 ], d1[ 5001 ][ 5001 ];
vector <int> v[ 100001 ];
queue <int> st;

void bfs( int u ) {
	for ( int i = 1; i <= n; i ++ )
		d[ i ] = oo;
	d[ u ] = 0;
	st.push( u );
	while ( st.size() ) {
		u = st.front();
		st.pop();
		for ( auto to : v[ u ] ) {
			if ( d[ to ] > d[ u ] + 1 ) {
				d[ to ] = d[ u ] + 1;
				st.push( to );
			}
		}
	}
}

main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ] >> b[ i ];
	}
	if ( n <= 5000 ) {
		for ( int i = 1; i <= n; i ++ ) {
			for ( int j = 1; j <= n; j ++ ) {
				if ( a[ j ] <= b[ i ] && b[ i ] <= b[ j ] && i != j ) {
					v[ i ].push_back( j );
				}
			}
		}
		for ( int i = 1; i <= n; i ++ ) {
			bfs( i );
			for ( int j = 1; j <= n; j ++ ) {
				d1[ i ][ j ] = d[ j ];
			}
		}
		while ( m -- ) {
			cin >> x >> y;
			if ( d1[ x ][ y ] == oo )
				cout << "impossible\n";
			else
				cout << d1[ x ][ y ] << "\n";
		}
		return 0;
	}
	else if ( m <= 100 ) {
		for ( int i = 1; i <= n; i ++ ) {
			
		}
		while ( m -- ) {
			cin >> x >> y;
			
		}  
	}
}

Compilation message

events.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 22 ms 3388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 20 ms 10672 KB Output is correct
4 Correct 15 ms 10632 KB Output is correct
5 Correct 19 ms 10580 KB Output is correct
6 Correct 63 ms 11344 KB Output is correct
7 Correct 166 ms 12204 KB Output is correct
8 Correct 206 ms 13272 KB Output is correct
9 Correct 1058 ms 14612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 20 ms 10672 KB Output is correct
4 Correct 15 ms 10632 KB Output is correct
5 Correct 19 ms 10580 KB Output is correct
6 Correct 63 ms 11344 KB Output is correct
7 Correct 166 ms 12204 KB Output is correct
8 Correct 206 ms 13272 KB Output is correct
9 Correct 1058 ms 14612 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 20 ms 10592 KB Output is correct
13 Correct 15 ms 10684 KB Output is correct
14 Correct 22 ms 10556 KB Output is correct
15 Correct 59 ms 11356 KB Output is correct
16 Correct 180 ms 12152 KB Output is correct
17 Correct 214 ms 13208 KB Output is correct
18 Correct 985 ms 14620 KB Output is correct
19 Execution timed out 1555 ms 41280 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 20 ms 10672 KB Output is correct
4 Correct 15 ms 10632 KB Output is correct
5 Correct 19 ms 10580 KB Output is correct
6 Correct 63 ms 11344 KB Output is correct
7 Correct 166 ms 12204 KB Output is correct
8 Correct 206 ms 13272 KB Output is correct
9 Correct 1058 ms 14612 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 18 ms 10580 KB Output is correct
13 Correct 14 ms 10656 KB Output is correct
14 Correct 22 ms 10628 KB Output is correct
15 Correct 52 ms 11384 KB Output is correct
16 Correct 141 ms 12256 KB Output is correct
17 Correct 169 ms 13184 KB Output is correct
18 Correct 904 ms 14644 KB Output is correct
19 Incorrect 20 ms 3416 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 3476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 22 ms 3388 KB Output isn't correct
3 Halted 0 ms 0 KB -