답안 #317713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317713 2020-10-30T07:43:07 Z ali_tavakoli Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
427 ms 262148 KB
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
//typedef sh short int
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast")

const int N = 3e4 + 5, M = 3e4 + 5, inf = 1e9 + 5;

int n, m, b[M], p[M], dis[M], mm = 2;
vector<int> adj[M];
vector<int> pos[N];
set<pair<int, int> > bp;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        cin >> b[i] >> p[i];
        if(i > 1)
            bp.insert({b[i], p[i]});
    }

    for(auto x : bp)
    {
        bool is = 1;
        if(is)
        {
            b[mm] = x.F;
            p[mm] = x.S;
            mm++;
        }
    }

    for(int i = 0; i < mm; i++)
        pos[b[i]].pb(i);

    for(int i = 0; i < mm; i++)
    {
        int ptr = b[i];
        while(ptr < n)
        {
            for(auto x : pos[ptr])
                adj[i].pb(x);
            ptr += p[i];
        }

        ptr = b[i] - p[i];
        while(ptr >= 0)
        {
            for(auto x : pos[ptr])
                adj[i].pb(x);
            ptr -= p[i];
        }
    }

    for(int i = 1; i < mm + 5; i++)
        dis[i] = inf;
    set<pair<int, int> > st;
    st.insert({0, 0});
    while(st.size())
    {
        auto x = *st.begin();
        //cout << x.S << endl;
        st.erase(x);
        for(auto v : adj[x.S])
        {
            int dist = abs(b[v] - b[x.S]) / p[x.S];
            if(x.F + dist < dis[v])
            {
                dis[v] = x.F + dist;
                st.insert({dis[v], v});
            }
        }
    }
    if(dis[1] == inf)
        cout << -1 << endl;
    else
        cout << dis[1] << endl;
    //cout << dis[1] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 1 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 1 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 1 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 8 ms 3072 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 8 ms 2944 KB Output is correct
15 Correct 8 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1792 KB Output is correct
2 Correct 1 ms 1920 KB Output is correct
3 Correct 2 ms 1792 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 8 ms 3072 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 8 ms 2944 KB Output is correct
15 Correct 8 ms 2944 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 5 ms 2304 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 61 ms 18048 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 4 ms 2048 KB Output is correct
25 Correct 4 ms 2176 KB Output is correct
26 Correct 2 ms 1792 KB Output is correct
27 Correct 2 ms 1920 KB Output is correct
28 Correct 3 ms 2176 KB Output is correct
29 Correct 3 ms 2048 KB Output is correct
30 Correct 2 ms 1920 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1792 KB Output is correct
33 Correct 8 ms 2944 KB Output is correct
34 Correct 8 ms 2976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 2 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 1 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 2 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 1792 KB Output is correct
11 Correct 8 ms 2944 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 8 ms 2944 KB Output is correct
15 Correct 8 ms 2944 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 6 ms 2304 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 59 ms 18168 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 4 ms 2048 KB Output is correct
25 Correct 4 ms 2176 KB Output is correct
26 Correct 2 ms 1792 KB Output is correct
27 Correct 2 ms 1920 KB Output is correct
28 Correct 3 ms 2048 KB Output is correct
29 Correct 3 ms 2080 KB Output is correct
30 Correct 2 ms 1792 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 8 ms 2944 KB Output is correct
34 Correct 8 ms 2944 KB Output is correct
35 Correct 119 ms 21408 KB Output is correct
36 Correct 10 ms 2944 KB Output is correct
37 Correct 117 ms 21240 KB Output is correct
38 Correct 158 ms 27000 KB Output is correct
39 Correct 155 ms 27640 KB Output is correct
40 Correct 169 ms 27896 KB Output is correct
41 Correct 157 ms 26488 KB Output is correct
42 Correct 7 ms 2048 KB Output is correct
43 Correct 7 ms 2176 KB Output is correct
44 Correct 64 ms 18352 KB Output is correct
45 Correct 319 ms 52088 KB Output is correct
46 Correct 327 ms 52092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1792 KB Output is correct
2 Correct 1 ms 1792 KB Output is correct
3 Correct 1 ms 1792 KB Output is correct
4 Correct 2 ms 1792 KB Output is correct
5 Correct 1 ms 1792 KB Output is correct
6 Correct 2 ms 1792 KB Output is correct
7 Correct 1 ms 1792 KB Output is correct
8 Correct 1 ms 1792 KB Output is correct
9 Correct 1 ms 1792 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 8 ms 2944 KB Output is correct
12 Correct 2 ms 1792 KB Output is correct
13 Correct 2 ms 1792 KB Output is correct
14 Correct 8 ms 2944 KB Output is correct
15 Correct 8 ms 2944 KB Output is correct
16 Correct 2 ms 1920 KB Output is correct
17 Correct 5 ms 2304 KB Output is correct
18 Correct 2 ms 1920 KB Output is correct
19 Correct 2 ms 1792 KB Output is correct
20 Correct 59 ms 18172 KB Output is correct
21 Correct 2 ms 1920 KB Output is correct
22 Correct 2 ms 1792 KB Output is correct
23 Correct 2 ms 1920 KB Output is correct
24 Correct 4 ms 2048 KB Output is correct
25 Correct 4 ms 2176 KB Output is correct
26 Correct 2 ms 1792 KB Output is correct
27 Correct 3 ms 1920 KB Output is correct
28 Correct 3 ms 2048 KB Output is correct
29 Correct 3 ms 2048 KB Output is correct
30 Correct 2 ms 1792 KB Output is correct
31 Correct 2 ms 1920 KB Output is correct
32 Correct 2 ms 1920 KB Output is correct
33 Correct 8 ms 2944 KB Output is correct
34 Correct 9 ms 2976 KB Output is correct
35 Correct 118 ms 21368 KB Output is correct
36 Correct 9 ms 2944 KB Output is correct
37 Correct 117 ms 21240 KB Output is correct
38 Correct 157 ms 27000 KB Output is correct
39 Correct 149 ms 27640 KB Output is correct
40 Correct 166 ms 27896 KB Output is correct
41 Correct 153 ms 26616 KB Output is correct
42 Correct 7 ms 2048 KB Output is correct
43 Correct 7 ms 2176 KB Output is correct
44 Correct 64 ms 18272 KB Output is correct
45 Correct 326 ms 52088 KB Output is correct
46 Correct 324 ms 52344 KB Output is correct
47 Correct 154 ms 18680 KB Output is correct
48 Correct 25 ms 5248 KB Output is correct
49 Correct 20 ms 4608 KB Output is correct
50 Correct 14 ms 3840 KB Output is correct
51 Correct 84 ms 9848 KB Output is correct
52 Correct 81 ms 9848 KB Output is correct
53 Correct 40 ms 7288 KB Output is correct
54 Correct 1 ms 1792 KB Output is correct
55 Correct 2 ms 1920 KB Output is correct
56 Runtime error 427 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -