Submission #388821

# Submission time Handle Problem Language Result Execution time Memory
388821 2021-04-13T05:26:01 Z talant117408 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1000 ms 1788 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 998244353;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

const int N = 3e4+7;
int dist[N], who[N];
vector <pii> graph[N];

int main() {
    //~ do_not_disturb
    
    int h, n;
    cin >> h >> n;
    
    vector <pii> doges(n);
    set <int> st;
    for (auto &to : doges) {
		cin >> to.first >> to.second;
	}
    for (int i = 0; i < n; i++) {
		who[doges[i].first]++;
		st.insert(doges[i].second);
	}
	
	vector <int> powers;
	for (auto to : st) powers.pb(to);
	reverse(all(powers));
	
	set <int> by_power[h];
	for (int i = 0; i < n; i++) {
		by_power[doges[i].second].insert(doges[i].first);
	}
	
	for (int i = 0; i < sz(powers); i++) {
		auto p = powers[i];
		for (auto b : by_power[p]) {
			int cnt = 0;
			for (int pos = b; pos < h; pos += p) {
				auto it = lb(all(graph[b]), mp(pos, 0));
				if (it == graph[b].end() || (*it).first != pos) {
					graph[b].pb(mp(pos, cnt));
				}
				cnt++;
			}
			cnt = 0;
			for (int pos = b; pos >= 0; pos -= p) {
				auto it = lb(all(graph[b]), mp(pos, 0));
				if (it == graph[b].end() || (*it).first != pos) {
					graph[b].pb(mp(pos, cnt));
				}
				cnt++;
			}
		}
	}
	
	for (int i = 0; i < h; i++) {
		dist[i] = 1e9;
	}
	dist[doges[0].first] = 0;
	priority_queue <pii> K;
	K.push(mp(0, doges[0].first));
	
	while(!K.empty()) {
		auto v = K.top().second; K.pop();
		for (auto to : graph[v]) {
			if (dist[to.first] > dist[v]+to.second) {
				dist[to.first] = dist[v]+to.second;
				K.push(mp(-dist[to.first], to.first));
			}
		}
	}
	
	if (dist[doges[1].first] >= 1e9) cout << -1;
	else cout << dist[doges[1].first];
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Execution timed out 1088 ms 972 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 2 ms 1740 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 2 ms 1768 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Runtime error 2 ms 1788 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Execution timed out 1078 ms 972 KB Time limit exceeded
3 Halted 0 ms 0 KB -