답안 #795395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795395 2023-07-27T09:00:26 Z nnhzzz Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
638 ms 16460 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024 :>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>

using namespace std;

#define    SORT_UNIQUE(v)  sort(ALL(v)),(v).resize(unique(ALL(v))-(v).begin())
#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define           RALL(x)  (x).rbegin(),(x).rend()
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define               INF  0x3f3f3f3f
#define                ll  long long
#define               ull  unsigned long long
#define                ld  long double
#define                vi  vector<int>
#define               vvi  vector<vi>
#define              vvvi  vector<vvi>
#define             vvvvi  vector<vvvi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define      RESET(x,val)  memset((x),(val),sizeof(x))
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
//-------------------------------------------------------------//
const int oo = 1e9,LOG = 20,MAXN = 5e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int dis[MAXN];
vi adj[MAXN];

void solve(){
    int st,en,n,m; cin >> n >> m;
    REP(i,0,m-1){
        int b,p; cin >> b >> p;
        if(i==0){
            st = b;
        }
        if(i==1){
            en = b;
        }
        adj[b].push_back(p);
    }
    memset(dis,0x3f3f3f3f,sizeof dis);
    priority_queue<pii,vpii,greater<pii>> heap;
    heap.emplace(0,st); dis[st] = 0;
    while(SZ(heap)!=0){
        auto [ww,u] = heap.top(); heap.pop();
        if(dis[u]!=ww){
            continue;
        }
        if(u==en){
            cout << dis[u];
            return ;
        }
        for(auto l:adj[u]){
            for(int i = 1; u+(l*i)<n; i++){
                int v = u+(l*i);
                if(mini(dis[v],dis[u]+i)){
                    heap.emplace(dis[v],v);
                }
            }
            for(int i = 1; u-(l*i)>=0; i++){
                int v = u-(l*i);
                if(mini(dis[v],dis[u]+i)){
                    heap.emplace(dis[v],v);
                }
            }
        }
    }
    int res = dis[en];
    if(res==0x3f3f3f3f){
        res = -1;
    }
    cout << res;
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "nnhzzz"
    if(fopen(name1".inp","r")){
        freopen(name1".inp","r",stdin);
        freopen(name1".out","w",stdout);
    }

    int test = 1;

    while(test--){
      solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:105:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |         auto [ww,u] = heap.top(); heap.pop();
      |              ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:140:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  140 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:141:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:103:33: warning: 'st' may be used uninitialized in this function [-Wmaybe-uninitialized]
  103 |     heap.emplace(0,st); dis[st] = 0;
      |                         ~~~~~~~~^~~
skyscraper.cpp:109:9: warning: 'en' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |         if(u==en){
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 13908 KB Output is correct
2 Correct 5 ms 13908 KB Output is correct
3 Correct 7 ms 13908 KB Output is correct
4 Correct 7 ms 13908 KB Output is correct
5 Correct 7 ms 13948 KB Output is correct
6 Correct 6 ms 13908 KB Output is correct
7 Correct 6 ms 13908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 13984 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Correct 7 ms 13908 KB Output is correct
4 Correct 6 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 8 ms 13980 KB Output is correct
7 Correct 7 ms 13908 KB Output is correct
8 Correct 8 ms 13908 KB Output is correct
9 Correct 8 ms 14004 KB Output is correct
10 Correct 5 ms 13960 KB Output is correct
11 Correct 9 ms 13980 KB Output is correct
12 Correct 8 ms 14036 KB Output is correct
13 Correct 7 ms 13992 KB Output is correct
14 Correct 7 ms 14036 KB Output is correct
15 Correct 5 ms 14036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13992 KB Output is correct
2 Correct 7 ms 13908 KB Output is correct
3 Correct 7 ms 13908 KB Output is correct
4 Correct 5 ms 13908 KB Output is correct
5 Correct 6 ms 13908 KB Output is correct
6 Correct 8 ms 13908 KB Output is correct
7 Correct 7 ms 13908 KB Output is correct
8 Correct 7 ms 13956 KB Output is correct
9 Correct 6 ms 13908 KB Output is correct
10 Correct 7 ms 14036 KB Output is correct
11 Correct 8 ms 14048 KB Output is correct
12 Correct 9 ms 14036 KB Output is correct
13 Correct 7 ms 14036 KB Output is correct
14 Correct 7 ms 14036 KB Output is correct
15 Correct 6 ms 14036 KB Output is correct
16 Correct 7 ms 14036 KB Output is correct
17 Correct 7 ms 14016 KB Output is correct
18 Correct 9 ms 14016 KB Output is correct
19 Correct 7 ms 14036 KB Output is correct
20 Correct 9 ms 14120 KB Output is correct
21 Correct 7 ms 14036 KB Output is correct
22 Correct 8 ms 14036 KB Output is correct
23 Correct 9 ms 14036 KB Output is correct
24 Correct 9 ms 13980 KB Output is correct
25 Correct 8 ms 13964 KB Output is correct
26 Correct 7 ms 14036 KB Output is correct
27 Correct 9 ms 14036 KB Output is correct
28 Correct 9 ms 13976 KB Output is correct
29 Correct 7 ms 14208 KB Output is correct
30 Correct 7 ms 14036 KB Output is correct
31 Correct 8 ms 14140 KB Output is correct
32 Correct 8 ms 14036 KB Output is correct
33 Correct 8 ms 14172 KB Output is correct
34 Correct 7 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13964 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Correct 7 ms 13908 KB Output is correct
4 Correct 6 ms 13964 KB Output is correct
5 Correct 8 ms 13908 KB Output is correct
6 Correct 6 ms 13908 KB Output is correct
7 Correct 8 ms 13908 KB Output is correct
8 Correct 7 ms 13908 KB Output is correct
9 Correct 7 ms 13908 KB Output is correct
10 Correct 8 ms 13932 KB Output is correct
11 Correct 7 ms 14036 KB Output is correct
12 Correct 7 ms 14008 KB Output is correct
13 Correct 9 ms 13968 KB Output is correct
14 Correct 6 ms 14036 KB Output is correct
15 Correct 7 ms 13952 KB Output is correct
16 Correct 6 ms 13908 KB Output is correct
17 Correct 7 ms 14036 KB Output is correct
18 Correct 6 ms 14036 KB Output is correct
19 Correct 7 ms 14036 KB Output is correct
20 Correct 10 ms 14036 KB Output is correct
21 Correct 8 ms 14036 KB Output is correct
22 Correct 7 ms 14036 KB Output is correct
23 Correct 7 ms 13956 KB Output is correct
24 Correct 7 ms 14020 KB Output is correct
25 Correct 7 ms 13984 KB Output is correct
26 Correct 8 ms 13936 KB Output is correct
27 Correct 7 ms 14036 KB Output is correct
28 Correct 9 ms 14036 KB Output is correct
29 Correct 8 ms 14164 KB Output is correct
30 Correct 7 ms 14036 KB Output is correct
31 Correct 7 ms 14036 KB Output is correct
32 Correct 6 ms 14140 KB Output is correct
33 Correct 9 ms 14268 KB Output is correct
34 Correct 7 ms 14164 KB Output is correct
35 Correct 12 ms 14268 KB Output is correct
36 Correct 7 ms 14100 KB Output is correct
37 Correct 9 ms 14240 KB Output is correct
38 Correct 15 ms 14324 KB Output is correct
39 Correct 10 ms 14156 KB Output is correct
40 Correct 10 ms 14164 KB Output is correct
41 Correct 11 ms 14248 KB Output is correct
42 Correct 10 ms 14284 KB Output is correct
43 Correct 9 ms 14164 KB Output is correct
44 Correct 64 ms 14244 KB Output is correct
45 Correct 11 ms 14372 KB Output is correct
46 Correct 11 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 13908 KB Output is correct
2 Correct 6 ms 13908 KB Output is correct
3 Correct 7 ms 13908 KB Output is correct
4 Correct 6 ms 13908 KB Output is correct
5 Correct 7 ms 13908 KB Output is correct
6 Correct 6 ms 13908 KB Output is correct
7 Correct 7 ms 13904 KB Output is correct
8 Correct 6 ms 13908 KB Output is correct
9 Correct 6 ms 13908 KB Output is correct
10 Correct 7 ms 13908 KB Output is correct
11 Correct 7 ms 13940 KB Output is correct
12 Correct 8 ms 14036 KB Output is correct
13 Correct 7 ms 14036 KB Output is correct
14 Correct 6 ms 14036 KB Output is correct
15 Correct 8 ms 13948 KB Output is correct
16 Correct 7 ms 14036 KB Output is correct
17 Correct 9 ms 14040 KB Output is correct
18 Correct 7 ms 14036 KB Output is correct
19 Correct 6 ms 14036 KB Output is correct
20 Correct 10 ms 14036 KB Output is correct
21 Correct 6 ms 14036 KB Output is correct
22 Correct 7 ms 14036 KB Output is correct
23 Correct 7 ms 14036 KB Output is correct
24 Correct 7 ms 14036 KB Output is correct
25 Correct 7 ms 14036 KB Output is correct
26 Correct 7 ms 14036 KB Output is correct
27 Correct 7 ms 14036 KB Output is correct
28 Correct 7 ms 14036 KB Output is correct
29 Correct 8 ms 14164 KB Output is correct
30 Correct 7 ms 14036 KB Output is correct
31 Correct 8 ms 14116 KB Output is correct
32 Correct 8 ms 14044 KB Output is correct
33 Correct 9 ms 14164 KB Output is correct
34 Correct 8 ms 14232 KB Output is correct
35 Correct 13 ms 14200 KB Output is correct
36 Correct 8 ms 14036 KB Output is correct
37 Correct 9 ms 14292 KB Output is correct
38 Correct 11 ms 14348 KB Output is correct
39 Correct 11 ms 14236 KB Output is correct
40 Correct 10 ms 14224 KB Output is correct
41 Correct 12 ms 14292 KB Output is correct
42 Correct 9 ms 14164 KB Output is correct
43 Correct 9 ms 14164 KB Output is correct
44 Correct 52 ms 14164 KB Output is correct
45 Correct 11 ms 14420 KB Output is correct
46 Correct 12 ms 14420 KB Output is correct
47 Correct 13 ms 14928 KB Output is correct
48 Correct 11 ms 14420 KB Output is correct
49 Correct 10 ms 14420 KB Output is correct
50 Correct 10 ms 14304 KB Output is correct
51 Correct 18 ms 15768 KB Output is correct
52 Correct 17 ms 15244 KB Output is correct
53 Correct 15 ms 14804 KB Output is correct
54 Correct 7 ms 14152 KB Output is correct
55 Correct 9 ms 14164 KB Output is correct
56 Correct 624 ms 15344 KB Output is correct
57 Correct 9 ms 14736 KB Output is correct
58 Correct 638 ms 14420 KB Output is correct
59 Correct 12 ms 14296 KB Output is correct
60 Correct 11 ms 14300 KB Output is correct
61 Correct 12 ms 14300 KB Output is correct
62 Correct 13 ms 14932 KB Output is correct
63 Correct 29 ms 15444 KB Output is correct
64 Correct 29 ms 16328 KB Output is correct
65 Correct 41 ms 16460 KB Output is correct
66 Correct 47 ms 16328 KB Output is correct
67 Correct 38 ms 16328 KB Output is correct