Submission #237334

# Submission time Handle Problem Language Result Execution time Memory
237334 2020-06-06T02:25:31 Z wwdd Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
446 ms 184456 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
const int SQ = 1500;
const int MN = 30030;
struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
	size_t operator()(ii x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(splitmix64(x.first+FIXED_RANDOM)+x.second+FIXED_RANDOM);
	}
};

unordered_map<ii,int, chash> dist;
ii ok[MN];
vi go[MN];
bitset<MN> vs;
int dx[2] = {-1,1};
int had[MN][SQ];
int ged(int u, int p) {
	if(p < SQ) {return had[u][p];}
	if(dist.count({u,p})) {
		return dist[{u,p}];
	}
	return -1;
}
void sed(int u, int p, int val) {
	if(p < SQ) {
		had[u][p] = val;
		return;}
	dist[{u,p}] = val;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	memset(had,-1,sizeof(had));
	for(int i=0;i<m;i++) {
		int a,p;
		cin >> a >> p;
		ok[i] = {a,p};
		go[a].push_back(p);
	}
	deque<ii> q;
	int sr = ok[0].first;
	vs.set(sr);
	for(int i=0;i<go[sr].size();i++) {
		if(ged(sr,go[sr][i]) == -1) {
			q.push_front({sr,go[sr][i]});
			sed(sr,go[sr][i],0);
		}
	}
	int res = -1;
	int fin = ok[1].first;
	while(!q.empty()) {
		ii co = q.front();q.pop_front();
		int u = co.first;
		int p = co.second;
		int di = ged(u,p);
		//cout << "look " << u << " " << p << " = " << di << '\n';
		if(u == fin) {
			res = di;break;
		}
		if(!vs[u]) {
			vs.set(u);
			//cout << "unlock " << u << '\n';
			for(int i=0;i<go[u].size();i++) {
				if(ged(u,go[u][i]) == -1) {
					q.push_front({u,go[u][i]});
					sed(u,go[u][i],di);
				}
			}
			q.push_front(co);
			continue;
		}
		for(int i=0;i<2;i++) {
			int v = u+dx[i]*p;
			if(v < 0 || v >= n) {continue;}
			if(ged(v,p) != -1) {continue;}
			sed(v,p,di+1);
			q.push_back({v,p});
		}
	}
	cout << res << '\n';
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<go[sr].size();i++) {
              ~^~~~~~~~~~~~~~
skyscraper.cpp:80:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<go[u].size();i++) {
                ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 177272 KB Output is correct
2 Correct 89 ms 177272 KB Output is correct
3 Correct 96 ms 177376 KB Output is correct
4 Correct 91 ms 177400 KB Output is correct
5 Correct 89 ms 177400 KB Output is correct
6 Correct 93 ms 177272 KB Output is correct
7 Correct 89 ms 177400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 177376 KB Output is correct
2 Correct 91 ms 177404 KB Output is correct
3 Correct 92 ms 177272 KB Output is correct
4 Correct 88 ms 177272 KB Output is correct
5 Correct 93 ms 177332 KB Output is correct
6 Correct 89 ms 177272 KB Output is correct
7 Correct 89 ms 177272 KB Output is correct
8 Correct 92 ms 177272 KB Output is correct
9 Correct 104 ms 177400 KB Output is correct
10 Correct 98 ms 177400 KB Output is correct
11 Correct 90 ms 177400 KB Output is correct
12 Correct 94 ms 177400 KB Output is correct
13 Correct 88 ms 177424 KB Output is correct
14 Correct 90 ms 177356 KB Output is correct
15 Correct 90 ms 177400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 177400 KB Output is correct
2 Correct 90 ms 177272 KB Output is correct
3 Correct 87 ms 177400 KB Output is correct
4 Correct 92 ms 177272 KB Output is correct
5 Correct 97 ms 177272 KB Output is correct
6 Correct 91 ms 177272 KB Output is correct
7 Correct 98 ms 177272 KB Output is correct
8 Correct 92 ms 177272 KB Output is correct
9 Correct 89 ms 177404 KB Output is correct
10 Correct 89 ms 177400 KB Output is correct
11 Correct 92 ms 177400 KB Output is correct
12 Correct 91 ms 177400 KB Output is correct
13 Correct 89 ms 177404 KB Output is correct
14 Correct 88 ms 177404 KB Output is correct
15 Correct 88 ms 177400 KB Output is correct
16 Correct 89 ms 177400 KB Output is correct
17 Correct 94 ms 177528 KB Output is correct
18 Correct 90 ms 177404 KB Output is correct
19 Correct 93 ms 177400 KB Output is correct
20 Correct 90 ms 177400 KB Output is correct
21 Correct 88 ms 177400 KB Output is correct
22 Correct 90 ms 177400 KB Output is correct
23 Correct 90 ms 177400 KB Output is correct
24 Correct 92 ms 177400 KB Output is correct
25 Correct 91 ms 177400 KB Output is correct
26 Correct 91 ms 177404 KB Output is correct
27 Correct 89 ms 177400 KB Output is correct
28 Correct 90 ms 177444 KB Output is correct
29 Correct 92 ms 177400 KB Output is correct
30 Correct 90 ms 177400 KB Output is correct
31 Correct 90 ms 177400 KB Output is correct
32 Correct 91 ms 177400 KB Output is correct
33 Correct 92 ms 177404 KB Output is correct
34 Correct 89 ms 177400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 177400 KB Output is correct
2 Correct 87 ms 177272 KB Output is correct
3 Correct 88 ms 177272 KB Output is correct
4 Correct 92 ms 177272 KB Output is correct
5 Correct 91 ms 177400 KB Output is correct
6 Correct 89 ms 177348 KB Output is correct
7 Correct 89 ms 177272 KB Output is correct
8 Correct 92 ms 177276 KB Output is correct
9 Correct 88 ms 177272 KB Output is correct
10 Correct 90 ms 177400 KB Output is correct
11 Correct 89 ms 177400 KB Output is correct
12 Correct 90 ms 177404 KB Output is correct
13 Correct 88 ms 177400 KB Output is correct
14 Correct 88 ms 177400 KB Output is correct
15 Correct 90 ms 177400 KB Output is correct
16 Correct 88 ms 177400 KB Output is correct
17 Correct 91 ms 177400 KB Output is correct
18 Correct 89 ms 177400 KB Output is correct
19 Correct 89 ms 177400 KB Output is correct
20 Correct 93 ms 177400 KB Output is correct
21 Correct 90 ms 177400 KB Output is correct
22 Correct 90 ms 177400 KB Output is correct
23 Correct 90 ms 177400 KB Output is correct
24 Correct 91 ms 177380 KB Output is correct
25 Correct 90 ms 177400 KB Output is correct
26 Correct 88 ms 177400 KB Output is correct
27 Correct 93 ms 177528 KB Output is correct
28 Correct 93 ms 177412 KB Output is correct
29 Correct 91 ms 177400 KB Output is correct
30 Correct 92 ms 177400 KB Output is correct
31 Correct 92 ms 177400 KB Output is correct
32 Correct 88 ms 177400 KB Output is correct
33 Correct 93 ms 177400 KB Output is correct
34 Correct 95 ms 177500 KB Output is correct
35 Correct 101 ms 178168 KB Output is correct
36 Correct 93 ms 177528 KB Output is correct
37 Correct 95 ms 177912 KB Output is correct
38 Correct 99 ms 178168 KB Output is correct
39 Correct 95 ms 177784 KB Output is correct
40 Correct 98 ms 177912 KB Output is correct
41 Correct 102 ms 178424 KB Output is correct
42 Correct 96 ms 177792 KB Output is correct
43 Correct 95 ms 178040 KB Output is correct
44 Correct 97 ms 177784 KB Output is correct
45 Correct 110 ms 178016 KB Output is correct
46 Correct 101 ms 178040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 177400 KB Output is correct
2 Correct 92 ms 177272 KB Output is correct
3 Correct 95 ms 177272 KB Output is correct
4 Correct 92 ms 177400 KB Output is correct
5 Correct 89 ms 177272 KB Output is correct
6 Correct 89 ms 177376 KB Output is correct
7 Correct 88 ms 177272 KB Output is correct
8 Correct 91 ms 177400 KB Output is correct
9 Correct 89 ms 177400 KB Output is correct
10 Correct 89 ms 177400 KB Output is correct
11 Correct 96 ms 177400 KB Output is correct
12 Correct 87 ms 177400 KB Output is correct
13 Correct 92 ms 177400 KB Output is correct
14 Correct 101 ms 177412 KB Output is correct
15 Correct 88 ms 177400 KB Output is correct
16 Correct 90 ms 177400 KB Output is correct
17 Correct 89 ms 177400 KB Output is correct
18 Correct 93 ms 177400 KB Output is correct
19 Correct 93 ms 177400 KB Output is correct
20 Correct 89 ms 177400 KB Output is correct
21 Correct 92 ms 177400 KB Output is correct
22 Correct 92 ms 177400 KB Output is correct
23 Correct 90 ms 177400 KB Output is correct
24 Correct 93 ms 177400 KB Output is correct
25 Correct 91 ms 177400 KB Output is correct
26 Correct 92 ms 177400 KB Output is correct
27 Correct 91 ms 177400 KB Output is correct
28 Correct 102 ms 177528 KB Output is correct
29 Correct 100 ms 177400 KB Output is correct
30 Correct 92 ms 177400 KB Output is correct
31 Correct 94 ms 177400 KB Output is correct
32 Correct 90 ms 177400 KB Output is correct
33 Correct 96 ms 177400 KB Output is correct
34 Correct 92 ms 177272 KB Output is correct
35 Correct 99 ms 178168 KB Output is correct
36 Correct 93 ms 177472 KB Output is correct
37 Correct 96 ms 177852 KB Output is correct
38 Correct 104 ms 178040 KB Output is correct
39 Correct 96 ms 177784 KB Output is correct
40 Correct 95 ms 177912 KB Output is correct
41 Correct 98 ms 178424 KB Output is correct
42 Correct 94 ms 177784 KB Output is correct
43 Correct 97 ms 177788 KB Output is correct
44 Correct 94 ms 177912 KB Output is correct
45 Correct 110 ms 178040 KB Output is correct
46 Correct 101 ms 178044 KB Output is correct
47 Correct 106 ms 178680 KB Output is correct
48 Correct 102 ms 177912 KB Output is correct
49 Correct 96 ms 177912 KB Output is correct
50 Correct 94 ms 177784 KB Output is correct
51 Correct 116 ms 180648 KB Output is correct
52 Correct 126 ms 181160 KB Output is correct
53 Correct 100 ms 178552 KB Output is correct
54 Correct 92 ms 177276 KB Output is correct
55 Correct 93 ms 177400 KB Output is correct
56 Correct 102 ms 178536 KB Output is correct
57 Correct 92 ms 177400 KB Output is correct
58 Correct 95 ms 177784 KB Output is correct
59 Correct 99 ms 178040 KB Output is correct
60 Correct 101 ms 178040 KB Output is correct
61 Correct 98 ms 178108 KB Output is correct
62 Correct 176 ms 184456 KB Output is correct
63 Correct 262 ms 178168 KB Output is correct
64 Correct 299 ms 178168 KB Output is correct
65 Correct 368 ms 178316 KB Output is correct
66 Correct 446 ms 178168 KB Output is correct
67 Correct 273 ms 178168 KB Output is correct