답안 #89893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89893 2018-12-18T19:21:59 Z nikolapesic2802 Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
213 ms 69340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
int n;
bool inside(int tr)
{
    return tr>=0&&tr<n;
}
int main()
{
    int m;
    scanf("%i %i",&n,&m);
    vector<set<int,greater<int> > > jumps(n);
    int b,p;
    scanf("%i %i",&b,&p);
    int start=b;
    jumps[b].insert(p);
    scanf("%i %i",&b,&p);
    int e=b;
    for(int i=2;i<m;i++)
    {
        scanf("%i %i",&b,&p);
        jumps[b].insert(p);
    }
    vector<vector<pair<int,int> > > graf(n);
    for(int i=0;i<n;i++)
    {
        for(auto p:jumps[i])
        {
            for(int j=1;;j++)
            {
                int pos=i+j*p;
                if(!inside(pos))
                    break;
                graf[i].pb({pos,j});
                if(jumps[pos].count(j))
                    break;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(auto p:jumps[i])
        {
            for(int j=1;;j++)
            {
                int pos=i-j*p;
                if(!inside(pos))
                    break;
                graf[i].pb({pos,j});
                if(jumps[pos].count(j))
                    break;
            }
        }
    }
    vector<int> done(n);
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int>> > q;
    q.push({0,start});
    fill(done.begin(),done.end(),INT_MAX);
    while(!q.empty())
    {
        int pos=q.top().second;
        int num=q.top().first;
        if(pos==e)
        {
            printf("%i\n",num);
            return 0;
        }
        q.pop();
        done[pos]=2;
        for(auto p:graf[pos])
        {
            if(done[p.first]>num+p.second)
            {
                q.push({num+p.second,p.first});
                done[p.first]=num+p.second;
            }
        }
    }
    printf("-1\n");
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&b,&p);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&b,&p);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&b,&p);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 524 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 728 KB Output is correct
2 Correct 2 ms 728 KB Output is correct
3 Correct 2 ms 728 KB Output is correct
4 Correct 2 ms 728 KB Output is correct
5 Correct 2 ms 728 KB Output is correct
6 Correct 2 ms 728 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
8 Correct 2 ms 728 KB Output is correct
9 Correct 2 ms 728 KB Output is correct
10 Correct 2 ms 728 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 768 KB Output is correct
2 Correct 2 ms 768 KB Output is correct
3 Correct 2 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 3 ms 768 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 3 ms 768 KB Output is correct
16 Correct 3 ms 768 KB Output is correct
17 Correct 4 ms 892 KB Output is correct
18 Correct 3 ms 892 KB Output is correct
19 Correct 3 ms 892 KB Output is correct
20 Correct 5 ms 892 KB Output is correct
21 Correct 3 ms 892 KB Output is correct
22 Correct 3 ms 892 KB Output is correct
23 Correct 4 ms 892 KB Output is correct
24 Correct 4 ms 892 KB Output is correct
25 Correct 3 ms 892 KB Output is correct
26 Correct 3 ms 892 KB Output is correct
27 Correct 3 ms 892 KB Output is correct
28 Correct 4 ms 1020 KB Output is correct
29 Correct 5 ms 1404 KB Output is correct
30 Correct 3 ms 1404 KB Output is correct
31 Correct 6 ms 1404 KB Output is correct
32 Correct 2 ms 1404 KB Output is correct
33 Correct 6 ms 2044 KB Output is correct
34 Correct 7 ms 2044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2044 KB Output is correct
2 Correct 2 ms 2044 KB Output is correct
3 Correct 2 ms 2044 KB Output is correct
4 Correct 2 ms 2044 KB Output is correct
5 Correct 2 ms 2044 KB Output is correct
6 Correct 2 ms 2044 KB Output is correct
7 Correct 2 ms 2044 KB Output is correct
8 Correct 2 ms 2044 KB Output is correct
9 Correct 2 ms 2044 KB Output is correct
10 Correct 3 ms 2044 KB Output is correct
11 Correct 3 ms 2044 KB Output is correct
12 Correct 2 ms 2044 KB Output is correct
13 Correct 2 ms 2044 KB Output is correct
14 Correct 3 ms 2044 KB Output is correct
15 Correct 3 ms 2044 KB Output is correct
16 Correct 2 ms 2044 KB Output is correct
17 Correct 3 ms 2044 KB Output is correct
18 Correct 3 ms 2044 KB Output is correct
19 Correct 2 ms 2044 KB Output is correct
20 Correct 1 ms 2044 KB Output is correct
21 Correct 3 ms 2044 KB Output is correct
22 Correct 2 ms 2044 KB Output is correct
23 Correct 3 ms 2044 KB Output is correct
24 Correct 4 ms 2044 KB Output is correct
25 Correct 3 ms 2044 KB Output is correct
26 Correct 3 ms 2044 KB Output is correct
27 Correct 3 ms 2044 KB Output is correct
28 Correct 3 ms 2044 KB Output is correct
29 Correct 5 ms 2044 KB Output is correct
30 Correct 3 ms 2044 KB Output is correct
31 Correct 4 ms 2044 KB Output is correct
32 Correct 4 ms 2044 KB Output is correct
33 Correct 6 ms 2044 KB Output is correct
34 Correct 6 ms 2044 KB Output is correct
35 Correct 23 ms 2940 KB Output is correct
36 Correct 5 ms 2940 KB Output is correct
37 Correct 23 ms 3708 KB Output is correct
38 Correct 29 ms 3964 KB Output is correct
39 Correct 28 ms 3964 KB Output is correct
40 Correct 28 ms 3964 KB Output is correct
41 Correct 28 ms 3964 KB Output is correct
42 Correct 7 ms 3964 KB Output is correct
43 Correct 9 ms 3964 KB Output is correct
44 Correct 8 ms 3964 KB Output is correct
45 Correct 32 ms 6396 KB Output is correct
46 Correct 33 ms 6652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6652 KB Output is correct
2 Correct 2 ms 6652 KB Output is correct
3 Correct 2 ms 6652 KB Output is correct
4 Correct 2 ms 6652 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 2 ms 6652 KB Output is correct
7 Correct 2 ms 6652 KB Output is correct
8 Correct 2 ms 6652 KB Output is correct
9 Correct 2 ms 6652 KB Output is correct
10 Correct 2 ms 6652 KB Output is correct
11 Correct 3 ms 6652 KB Output is correct
12 Correct 2 ms 6652 KB Output is correct
13 Correct 2 ms 6652 KB Output is correct
14 Correct 3 ms 6652 KB Output is correct
15 Correct 3 ms 6652 KB Output is correct
16 Correct 2 ms 6652 KB Output is correct
17 Correct 4 ms 6652 KB Output is correct
18 Correct 3 ms 6652 KB Output is correct
19 Correct 3 ms 6652 KB Output is correct
20 Correct 3 ms 6652 KB Output is correct
21 Correct 2 ms 6652 KB Output is correct
22 Correct 2 ms 6652 KB Output is correct
23 Correct 3 ms 6652 KB Output is correct
24 Correct 4 ms 6652 KB Output is correct
25 Correct 3 ms 6652 KB Output is correct
26 Correct 3 ms 6652 KB Output is correct
27 Correct 3 ms 6652 KB Output is correct
28 Correct 3 ms 6652 KB Output is correct
29 Correct 5 ms 6652 KB Output is correct
30 Correct 3 ms 6652 KB Output is correct
31 Correct 4 ms 6652 KB Output is correct
32 Correct 3 ms 6652 KB Output is correct
33 Correct 7 ms 6652 KB Output is correct
34 Correct 7 ms 6652 KB Output is correct
35 Correct 22 ms 6652 KB Output is correct
36 Correct 5 ms 6652 KB Output is correct
37 Correct 24 ms 6652 KB Output is correct
38 Correct 29 ms 6652 KB Output is correct
39 Correct 30 ms 6652 KB Output is correct
40 Correct 30 ms 6652 KB Output is correct
41 Correct 34 ms 6652 KB Output is correct
42 Correct 9 ms 6652 KB Output is correct
43 Correct 8 ms 6652 KB Output is correct
44 Correct 9 ms 6652 KB Output is correct
45 Correct 32 ms 6652 KB Output is correct
46 Correct 31 ms 6864 KB Output is correct
47 Correct 56 ms 12068 KB Output is correct
48 Correct 26 ms 12068 KB Output is correct
49 Correct 21 ms 12068 KB Output is correct
50 Correct 16 ms 12068 KB Output is correct
51 Correct 47 ms 12068 KB Output is correct
52 Correct 53 ms 12068 KB Output is correct
53 Correct 23 ms 12068 KB Output is correct
54 Correct 6 ms 12068 KB Output is correct
55 Correct 8 ms 12068 KB Output is correct
56 Correct 19 ms 12068 KB Output is correct
57 Correct 125 ms 58868 KB Output is correct
58 Correct 14 ms 58868 KB Output is correct
59 Correct 14 ms 58868 KB Output is correct
60 Correct 18 ms 58868 KB Output is correct
61 Correct 18 ms 58868 KB Output is correct
62 Correct 34 ms 58868 KB Output is correct
63 Correct 98 ms 58868 KB Output is correct
64 Correct 112 ms 58868 KB Output is correct
65 Correct 144 ms 58868 KB Output is correct
66 Correct 207 ms 69128 KB Output is correct
67 Correct 213 ms 69340 KB Output is correct