답안 #398422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398422 2021-05-04T09:01:13 Z amunduzbaev Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
476 ms 112536 KB
/* made by amunduzbaev */
 
#include <bits/stdc++.h>
 
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define tut(x) array<int, x> 
//#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii; 
typedef vector<int> vii;
typedef vector<pii> vpii;
 
template<class T> bool umin(T& a, const T& b) { return a > b? a = b, true:false; }
template<class T> bool umax(T& a, const T& b) { return a < b? a = b, true:false; }
//void usaco(string s) { freopen((s+".in").c_str(),"r",stdin);  
	//freopen((s+".out").c_str(),"w",stdout); }
//template<class T> tree<T, 
//less<T>, null_type, rb_tree_tag, 
//tree_order_statistics_node_update> ordered_set;
 
const int N = 3e4+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
const int M = 2e3+5;
const int B = 500;
 
#define MULTI 0
int n, m, K, s, ans, q, res, a[N];
bitset<N> used, vis[N];
int b[N], p[N];
vii cnt[N];

void solve(int t_case){
	cin>>m>>n;
	for(int i=0;i<n;i++) cin>>b[i]>>p[i], cnt[b[i]].pb(p[i]);
	deque<tut(3)> qq; 
	qq.pb({b[0], p[0], 0}); 
	while(!qq.empty()){
		auto cur = qq.front(); qq.pop_front();
		vis[cur[0]][cur[1]] = 1;
		if(cur[0] == b[1]) { cout<<cur[2]; return; }   
		
		if(!used[cur[0]]){
			for(auto x : cnt[cur[0]]){
				if(vis[cur[0]][x]) continue;
				vis[cur[0]][x] = 1, qq.push_front({cur[0], x, cur[2]});
			} 
		} used[cur[0]] = 1;
		
		if(cur[0] + cur[1] < m && !vis[cur[0] + cur[1]][cur[1]]) qq.pb({cur[0] + cur[1], cur[1], cur[2] + 1}); 
		if(cur[0] - cur[1] >= 0 && !vis[cur[0] - cur[1]][cur[1]]) qq.pb({cur[0] - cur[1], cur[1], cur[2] + 1}); 
	} cout<<-1<<"\n";
}
 
signed main(){ 
	NeedForSpeed
	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	} return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 3 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 2 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1104 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1360 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 7 ms 8396 KB Output is correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6348 KB Output is correct
24 Correct 7 ms 7500 KB Output is correct
25 Correct 3 ms 2380 KB Output is correct
26 Correct 9 ms 7244 KB Output is correct
27 Correct 6 ms 7628 KB Output is correct
28 Correct 7 ms 8396 KB Output is correct
29 Correct 9 ms 8396 KB Output is correct
30 Correct 6 ms 8372 KB Output is correct
31 Correct 8 ms 8268 KB Output is correct
32 Correct 7 ms 8396 KB Output is correct
33 Correct 9 ms 8436 KB Output is correct
34 Correct 8 ms 8424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 1 ms 1100 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 2 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 7 ms 8524 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6348 KB Output is correct
24 Correct 8 ms 7492 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 6 ms 7244 KB Output is correct
27 Correct 6 ms 7628 KB Output is correct
28 Correct 7 ms 8396 KB Output is correct
29 Correct 8 ms 8396 KB Output is correct
30 Correct 6 ms 8268 KB Output is correct
31 Correct 7 ms 8268 KB Output is correct
32 Correct 7 ms 8268 KB Output is correct
33 Correct 10 ms 8340 KB Output is correct
34 Correct 8 ms 8400 KB Output is correct
35 Correct 12 ms 6820 KB Output is correct
36 Correct 3 ms 2252 KB Output is correct
37 Correct 10 ms 6476 KB Output is correct
38 Correct 11 ms 4812 KB Output is correct
39 Correct 8 ms 1484 KB Output is correct
40 Correct 9 ms 2380 KB Output is correct
41 Correct 11 ms 3116 KB Output is correct
42 Correct 12 ms 7712 KB Output is correct
43 Correct 10 ms 8012 KB Output is correct
44 Correct 12 ms 8780 KB Output is correct
45 Correct 25 ms 9164 KB Output is correct
46 Correct 18 ms 9060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1100 KB Output is correct
11 Correct 2 ms 1104 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 4 ms 3404 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 7 ms 8396 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6320 KB Output is correct
24 Correct 6 ms 7500 KB Output is correct
25 Correct 3 ms 2380 KB Output is correct
26 Correct 6 ms 7244 KB Output is correct
27 Correct 7 ms 7628 KB Output is correct
28 Correct 9 ms 8396 KB Output is correct
29 Correct 8 ms 8312 KB Output is correct
30 Correct 7 ms 8364 KB Output is correct
31 Correct 7 ms 8396 KB Output is correct
32 Correct 7 ms 8268 KB Output is correct
33 Correct 9 ms 8396 KB Output is correct
34 Correct 9 ms 8352 KB Output is correct
35 Correct 13 ms 6860 KB Output is correct
36 Correct 3 ms 2252 KB Output is correct
37 Correct 10 ms 6580 KB Output is correct
38 Correct 12 ms 4812 KB Output is correct
39 Correct 8 ms 1484 KB Output is correct
40 Correct 9 ms 2380 KB Output is correct
41 Correct 10 ms 3124 KB Output is correct
42 Correct 10 ms 7756 KB Output is correct
43 Correct 10 ms 8012 KB Output is correct
44 Correct 14 ms 8792 KB Output is correct
45 Correct 24 ms 9164 KB Output is correct
46 Correct 17 ms 9036 KB Output is correct
47 Correct 16 ms 10248 KB Output is correct
48 Correct 7 ms 1612 KB Output is correct
49 Correct 7 ms 1612 KB Output is correct
50 Correct 8 ms 1480 KB Output is correct
51 Correct 68 ms 81596 KB Output is correct
52 Correct 79 ms 89604 KB Output is correct
53 Correct 21 ms 18640 KB Output is correct
54 Correct 40 ms 61224 KB Output is correct
55 Correct 52 ms 77864 KB Output is correct
56 Correct 81 ms 112260 KB Output is correct
57 Correct 3 ms 2636 KB Output is correct
58 Correct 89 ms 111664 KB Output is correct
59 Correct 76 ms 103848 KB Output is correct
60 Correct 76 ms 104080 KB Output is correct
61 Correct 71 ms 98756 KB Output is correct
62 Correct 129 ms 112536 KB Output is correct
63 Correct 256 ms 111860 KB Output is correct
64 Correct 224 ms 111808 KB Output is correct
65 Correct 293 ms 111964 KB Output is correct
66 Correct 476 ms 111940 KB Output is correct
67 Correct 281 ms 111848 KB Output is correct