Submission #110033

# Submission time Handle Problem Language Result Execution time Memory
110033 2019-05-09T00:58:04 Z aminra Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
572 ms 95888 KB
//I forgot you...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = 3e4 + 3;
const int SQRT = (int)10;
const int infint = (int)1e9 + 3;
const ll inf = (ll)1e18;
int dist[MAXN * SQRT], ldir[MAXN][SQRT], rdir[MAXN][SQRT], n, m;
vector<pair<int, int> > G[SQRT * MAXN];
inline void add(int u, int v, int w)
{
	G[u].push_back({v, w});
}
int dijkstra(int src, int sink)
{
	for (int i = 0; i < MAXN * SQRT; i++)
		dist[i] = infint;
	
	dist[src] = 0;
	set<pair<int, int> > S;
	for (int i = 0; i < MAXN * SQRT; i++)
		S.insert({dist[i], i});
	while(!S.empty())
	{
		pair<int, int> st = *S.begin();
		S.erase(st);
		if(st.first == infint)
			continue;
		for (auto v : G[st.second])
			if(st.first + v.second < dist[v.first])
			{
				S.erase({dist[v.first], v.first});
				dist[v.first] = st.first + v.second;
				S.insert({dist[v.first], v.first});
			}
	}
	if(dist[sink] == infint)
		return -1;
	else
		return dist[sink];
}
int main()
{
	ios::sync_with_stdio(false); 
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	int src = -1, sink = -1;
	for (int i = 0; i < m; i++)
	{
		int b, p;
		cin >> b >> p;
		if(i == 0)
			src = b;
		if(i == 1)
			sink = b;

		if(p < SQRT)
		{
			ldir[b][p] = 1;
			rdir[b][p] = 1;
			add(b, b + n * p, 0);
		}
		else
		{
			for (int j = 1; b - j * p >= 0; j++)
                add(b, b - j * p, j);
            for (int j = 1; b + j * p < n; j++)
            	add(b, b + j * p, j);
		}
	}
	for (int i = 1; i < SQRT; i++)
	{
        for (int j = i; j < n; j++)
            rdir[j][i] |= rdir[j - i][i];
        for (int j = n - i - 1; j >= 0; j--)
            ldir[j][i] |= ldir[j + i][i];
    }
    for (int i = 1; i < SQRT; i++)
    	for (int j = 0; j < n - i; j++)
    		if(rdir[j][i])
    			add(j + n * i, j + (n + 1) * i, 1);
 
	 for (int i = 1; i < SQRT; i++)
	 	for (int j = i; j < n; j++)
		 	if(ldir[j][i])
		 		add(j + n * i, j + (n - 1) * i, 1);
	
	for (int i = 1; i < SQRT; i++)
		for (int j = 0; j < n; j++)
			add(j + n * i, j, 0);
	
    cout << dijkstra(src, sink);
}
# Verdict Execution time Memory Grader output
1 Correct 111 ms 22648 KB Output is correct
2 Correct 111 ms 22648 KB Output is correct
3 Correct 112 ms 22776 KB Output is correct
4 Correct 127 ms 22648 KB Output is correct
5 Correct 115 ms 22708 KB Output is correct
6 Correct 116 ms 22648 KB Output is correct
7 Correct 128 ms 22780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 22648 KB Output is correct
2 Correct 119 ms 22736 KB Output is correct
3 Correct 126 ms 22648 KB Output is correct
4 Correct 118 ms 22756 KB Output is correct
5 Correct 123 ms 22740 KB Output is correct
6 Correct 116 ms 22788 KB Output is correct
7 Correct 119 ms 22776 KB Output is correct
8 Correct 123 ms 22720 KB Output is correct
9 Correct 122 ms 22776 KB Output is correct
10 Correct 117 ms 22776 KB Output is correct
11 Correct 118 ms 22776 KB Output is correct
12 Correct 134 ms 22904 KB Output is correct
13 Correct 122 ms 22784 KB Output is correct
14 Correct 120 ms 22700 KB Output is correct
15 Correct 113 ms 22776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 22648 KB Output is correct
2 Correct 114 ms 22648 KB Output is correct
3 Correct 116 ms 22648 KB Output is correct
4 Correct 147 ms 22840 KB Output is correct
5 Correct 112 ms 22648 KB Output is correct
6 Correct 113 ms 22776 KB Output is correct
7 Correct 129 ms 22704 KB Output is correct
8 Correct 112 ms 22720 KB Output is correct
9 Correct 118 ms 22744 KB Output is correct
10 Correct 122 ms 22776 KB Output is correct
11 Correct 141 ms 22908 KB Output is correct
12 Correct 125 ms 22780 KB Output is correct
13 Correct 139 ms 22740 KB Output is correct
14 Correct 124 ms 22776 KB Output is correct
15 Correct 122 ms 22904 KB Output is correct
16 Correct 117 ms 22776 KB Output is correct
17 Correct 135 ms 23084 KB Output is correct
18 Correct 123 ms 23388 KB Output is correct
19 Correct 121 ms 23416 KB Output is correct
20 Correct 125 ms 23416 KB Output is correct
21 Correct 145 ms 22776 KB Output is correct
22 Correct 120 ms 23308 KB Output is correct
23 Correct 128 ms 23288 KB Output is correct
24 Correct 129 ms 23544 KB Output is correct
25 Correct 128 ms 23544 KB Output is correct
26 Correct 132 ms 23572 KB Output is correct
27 Correct 136 ms 23500 KB Output is correct
28 Correct 132 ms 23608 KB Output is correct
29 Correct 131 ms 23960 KB Output is correct
30 Correct 132 ms 23504 KB Output is correct
31 Correct 147 ms 23800 KB Output is correct
32 Correct 130 ms 23592 KB Output is correct
33 Correct 137 ms 24576 KB Output is correct
34 Correct 134 ms 24396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 22648 KB Output is correct
2 Correct 115 ms 22776 KB Output is correct
3 Correct 108 ms 22648 KB Output is correct
4 Correct 117 ms 22648 KB Output is correct
5 Correct 118 ms 22776 KB Output is correct
6 Correct 121 ms 22628 KB Output is correct
7 Correct 135 ms 22744 KB Output is correct
8 Correct 118 ms 22648 KB Output is correct
9 Correct 112 ms 22648 KB Output is correct
10 Correct 117 ms 22792 KB Output is correct
11 Correct 112 ms 22904 KB Output is correct
12 Correct 118 ms 22776 KB Output is correct
13 Correct 133 ms 22776 KB Output is correct
14 Correct 123 ms 22776 KB Output is correct
15 Correct 122 ms 22776 KB Output is correct
16 Correct 114 ms 22776 KB Output is correct
17 Correct 118 ms 23040 KB Output is correct
18 Correct 117 ms 23288 KB Output is correct
19 Correct 115 ms 23416 KB Output is correct
20 Correct 126 ms 23640 KB Output is correct
21 Correct 159 ms 22776 KB Output is correct
22 Correct 127 ms 23516 KB Output is correct
23 Correct 134 ms 23364 KB Output is correct
24 Correct 132 ms 23516 KB Output is correct
25 Correct 132 ms 23544 KB Output is correct
26 Correct 124 ms 23524 KB Output is correct
27 Correct 134 ms 23416 KB Output is correct
28 Correct 127 ms 23544 KB Output is correct
29 Correct 128 ms 24056 KB Output is correct
30 Correct 123 ms 23636 KB Output is correct
31 Correct 118 ms 23644 KB Output is correct
32 Correct 118 ms 23748 KB Output is correct
33 Correct 127 ms 24440 KB Output is correct
34 Correct 150 ms 24440 KB Output is correct
35 Correct 127 ms 24284 KB Output is correct
36 Correct 116 ms 23292 KB Output is correct
37 Correct 154 ms 25688 KB Output is correct
38 Correct 138 ms 25336 KB Output is correct
39 Correct 144 ms 25336 KB Output is correct
40 Correct 179 ms 25436 KB Output is correct
41 Correct 189 ms 25336 KB Output is correct
42 Correct 129 ms 23924 KB Output is correct
43 Correct 132 ms 23808 KB Output is correct
44 Correct 127 ms 23836 KB Output is correct
45 Correct 157 ms 27956 KB Output is correct
46 Correct 159 ms 27876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 22804 KB Output is correct
2 Correct 119 ms 22740 KB Output is correct
3 Correct 120 ms 22792 KB Output is correct
4 Correct 116 ms 22648 KB Output is correct
5 Correct 121 ms 22648 KB Output is correct
6 Correct 123 ms 22736 KB Output is correct
7 Correct 117 ms 22732 KB Output is correct
8 Correct 127 ms 22756 KB Output is correct
9 Correct 124 ms 22648 KB Output is correct
10 Correct 133 ms 22872 KB Output is correct
11 Correct 122 ms 22776 KB Output is correct
12 Correct 120 ms 22760 KB Output is correct
13 Correct 125 ms 22704 KB Output is correct
14 Correct 120 ms 22748 KB Output is correct
15 Correct 118 ms 22696 KB Output is correct
16 Correct 117 ms 22820 KB Output is correct
17 Correct 125 ms 23112 KB Output is correct
18 Correct 153 ms 23376 KB Output is correct
19 Correct 114 ms 23360 KB Output is correct
20 Correct 119 ms 23660 KB Output is correct
21 Correct 114 ms 22780 KB Output is correct
22 Correct 117 ms 23416 KB Output is correct
23 Correct 125 ms 23380 KB Output is correct
24 Correct 127 ms 23416 KB Output is correct
25 Correct 118 ms 23532 KB Output is correct
26 Correct 115 ms 23416 KB Output is correct
27 Correct 120 ms 23500 KB Output is correct
28 Correct 135 ms 23596 KB Output is correct
29 Correct 149 ms 23992 KB Output is correct
30 Correct 129 ms 23544 KB Output is correct
31 Correct 138 ms 23792 KB Output is correct
32 Correct 137 ms 23800 KB Output is correct
33 Correct 138 ms 24420 KB Output is correct
34 Correct 131 ms 24440 KB Output is correct
35 Correct 130 ms 24372 KB Output is correct
36 Correct 129 ms 23260 KB Output is correct
37 Correct 147 ms 25612 KB Output is correct
38 Correct 149 ms 25300 KB Output is correct
39 Correct 148 ms 25464 KB Output is correct
40 Correct 139 ms 25208 KB Output is correct
41 Correct 132 ms 25208 KB Output is correct
42 Correct 132 ms 23996 KB Output is correct
43 Correct 146 ms 23800 KB Output is correct
44 Correct 150 ms 23824 KB Output is correct
45 Correct 143 ms 27896 KB Output is correct
46 Correct 141 ms 27768 KB Output is correct
47 Correct 314 ms 35704 KB Output is correct
48 Correct 177 ms 33080 KB Output is correct
49 Correct 148 ms 33392 KB Output is correct
50 Correct 142 ms 34144 KB Output is correct
51 Correct 257 ms 36444 KB Output is correct
52 Correct 268 ms 36860 KB Output is correct
53 Correct 197 ms 34424 KB Output is correct
54 Correct 143 ms 33528 KB Output is correct
55 Correct 159 ms 33968 KB Output is correct
56 Correct 175 ms 35212 KB Output is correct
57 Correct 419 ms 60412 KB Output is correct
58 Correct 181 ms 34420 KB Output is correct
59 Correct 187 ms 34560 KB Output is correct
60 Correct 200 ms 35580 KB Output is correct
61 Correct 192 ms 34292 KB Output is correct
62 Correct 307 ms 37752 KB Output is correct
63 Correct 353 ms 55800 KB Output is correct
64 Correct 375 ms 61020 KB Output is correct
65 Correct 345 ms 69288 KB Output is correct
66 Correct 572 ms 95532 KB Output is correct
67 Correct 561 ms 95888 KB Output is correct