Submission #674090

# Submission time Handle Problem Language Result Execution time Memory
674090 2022-12-23T03:09:43 Z lmqzzz Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 29960 KB
#include<bits/stdc++.h>
using namespace std;

#define           fi    first
#define           se    second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int32_t)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define         left    Kurumi_Tokisaki
#define        right    Kei_Karuizawa
#define         next    Mai_Sakurajima
#define          div    Yume_Irido
#define         prev    Chizuru_Mizuhara
#define    cntbit(x)    __builtin_popcountll(x)
#define      MASK(x)    ( 1ll << (x) )
#define          Yes    cout << "Yes"
#define          YES    cout << "YES"
#define           No    cout << "No"
#define           NO    cout << "NO"
#define           AA    cout << "Alice"
#define           BB    cout << "Bob"

/// TASK
/// -----------------------------
#ifdef LMQZZZ
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << " ]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define deb(x...) cerr << "[ in " <<__func__<< "() : line " <<__LINE__<< " ] : [ " << #x << " ] = [ "; _print(x); cerr << '\n';
#define TASK "C"
#else
#define deb(x...) 3326
#define TASK "Sky"
#endif
///------------------------------

void lmqzzz();
void init() {};
int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);      cout.tie(0);
        if (fopen(TASK ".inp", "r")) {
                freopen(TASK ".inp", "r", stdin);
                freopen(TASK ".out", "w", stdout);
        }
        /// =================================
                constexpr bool MULTITEST = 0;
        /// ================================
        init();
        int32_t TT = 1;
        if ( MULTITEST ) cin >> TT;
        for(int32_t TTT = 1; TTT <= TT; TTT ++) {
                lmqzzz();
                cout << '\n';
        }
}

template <class T> inline T min(const T &a, const T &b, const T &c) { return min(a, min(b, c)); }
template <class T> inline T max(const T &a, const T &b, const T &c) { return max(a, max(b, c)); }
template <class T, class U> inline bool mini(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; }
template <class T, class U> inline bool maxi(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; }

constexpr     int16_t dr[]  =  {0, 0, -1, 1};
constexpr     int16_t dc[]  =  {1, -1, 0, 0};
constexpr      int64_t MOD  =  1e9 + 7;
constexpr     int32_t MAXN  =  1e6 + 10;

int n, m;
int b[MAXN], p[MAXN], d[MAXN];
vector<int> adj[MAXN];

void lmqzzz() {
        cin >> n >> m;
        for (int i = 0; i < m; i ++) {
                cin >> b[i] >> p[i];
                adj[b[i]].eb(p[i]);
        }
        priority_queue<pair<int, int>> pq;
        pq.ep(0, b[0]);
        mem(d, 0x3f);
        d[b[0]] = 0;

        while (sz(pq)) {
                int u = pq.top().se;
                int du = -pq.top().fi;
                pq.pop();
                if (du != d[u]) continue;
                if (u == b[1]) {
                        cout << du;
                        return;
                }
                for (int w : adj[u]) {
                        for (int next = u % w; next < n; next += w) {
                                if (mini(d[next], du + abs(next - u) / w)) {
                                        pq.ep(-d[next], next);
                                }
                        }
                }
        }
        cout << -1;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:72:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |                 freopen(TASK ".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:73:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |                 freopen(TASK ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27604 KB Output is correct
2 Correct 12 ms 27732 KB Output is correct
3 Correct 13 ms 27712 KB Output is correct
4 Correct 13 ms 27728 KB Output is correct
5 Correct 13 ms 27604 KB Output is correct
6 Correct 13 ms 27652 KB Output is correct
7 Correct 13 ms 27732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 27684 KB Output is correct
2 Correct 13 ms 27732 KB Output is correct
3 Correct 12 ms 27732 KB Output is correct
4 Correct 14 ms 27732 KB Output is correct
5 Correct 13 ms 27604 KB Output is correct
6 Correct 12 ms 27612 KB Output is correct
7 Correct 12 ms 27696 KB Output is correct
8 Correct 15 ms 27676 KB Output is correct
9 Correct 13 ms 27660 KB Output is correct
10 Correct 13 ms 27652 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 14 ms 27732 KB Output is correct
13 Correct 18 ms 27664 KB Output is correct
14 Correct 14 ms 27748 KB Output is correct
15 Correct 13 ms 27788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27732 KB Output is correct
2 Correct 15 ms 27732 KB Output is correct
3 Correct 13 ms 27732 KB Output is correct
4 Correct 14 ms 27688 KB Output is correct
5 Correct 15 ms 27604 KB Output is correct
6 Correct 13 ms 27648 KB Output is correct
7 Correct 13 ms 27684 KB Output is correct
8 Correct 14 ms 27728 KB Output is correct
9 Correct 14 ms 27732 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 14 ms 27732 KB Output is correct
12 Correct 15 ms 27716 KB Output is correct
13 Correct 15 ms 27732 KB Output is correct
14 Correct 13 ms 27784 KB Output is correct
15 Correct 13 ms 27732 KB Output is correct
16 Correct 14 ms 27720 KB Output is correct
17 Correct 14 ms 27820 KB Output is correct
18 Correct 14 ms 27724 KB Output is correct
19 Correct 14 ms 27732 KB Output is correct
20 Correct 38 ms 27796 KB Output is correct
21 Correct 14 ms 27664 KB Output is correct
22 Correct 14 ms 27744 KB Output is correct
23 Correct 14 ms 27716 KB Output is correct
24 Correct 14 ms 27732 KB Output is correct
25 Correct 14 ms 27768 KB Output is correct
26 Correct 14 ms 27784 KB Output is correct
27 Correct 13 ms 27796 KB Output is correct
28 Correct 13 ms 27796 KB Output is correct
29 Correct 14 ms 27784 KB Output is correct
30 Correct 13 ms 27760 KB Output is correct
31 Correct 15 ms 27780 KB Output is correct
32 Correct 16 ms 27852 KB Output is correct
33 Correct 15 ms 27916 KB Output is correct
34 Correct 14 ms 27920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 27696 KB Output is correct
2 Correct 12 ms 27732 KB Output is correct
3 Correct 13 ms 27604 KB Output is correct
4 Correct 17 ms 27640 KB Output is correct
5 Correct 16 ms 27732 KB Output is correct
6 Correct 13 ms 27736 KB Output is correct
7 Correct 13 ms 27604 KB Output is correct
8 Correct 15 ms 27732 KB Output is correct
9 Correct 13 ms 27652 KB Output is correct
10 Correct 13 ms 27732 KB Output is correct
11 Correct 14 ms 27704 KB Output is correct
12 Correct 16 ms 27692 KB Output is correct
13 Correct 14 ms 27664 KB Output is correct
14 Correct 14 ms 27792 KB Output is correct
15 Correct 14 ms 27736 KB Output is correct
16 Correct 15 ms 27732 KB Output is correct
17 Correct 14 ms 27792 KB Output is correct
18 Correct 13 ms 27792 KB Output is correct
19 Correct 13 ms 27732 KB Output is correct
20 Correct 37 ms 27800 KB Output is correct
21 Correct 14 ms 27732 KB Output is correct
22 Correct 15 ms 27732 KB Output is correct
23 Correct 14 ms 27732 KB Output is correct
24 Correct 14 ms 27732 KB Output is correct
25 Correct 13 ms 27792 KB Output is correct
26 Correct 15 ms 27732 KB Output is correct
27 Correct 14 ms 27676 KB Output is correct
28 Correct 14 ms 27728 KB Output is correct
29 Correct 14 ms 27860 KB Output is correct
30 Correct 14 ms 27844 KB Output is correct
31 Correct 14 ms 27860 KB Output is correct
32 Correct 14 ms 27732 KB Output is correct
33 Correct 15 ms 27860 KB Output is correct
34 Correct 15 ms 27872 KB Output is correct
35 Correct 23 ms 28436 KB Output is correct
36 Correct 17 ms 27988 KB Output is correct
37 Correct 18 ms 28244 KB Output is correct
38 Correct 20 ms 28456 KB Output is correct
39 Correct 18 ms 28416 KB Output is correct
40 Correct 19 ms 28504 KB Output is correct
41 Correct 20 ms 28524 KB Output is correct
42 Correct 16 ms 28372 KB Output is correct
43 Correct 16 ms 28372 KB Output is correct
44 Correct 379 ms 28404 KB Output is correct
45 Correct 21 ms 28432 KB Output is correct
46 Correct 23 ms 28484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 27732 KB Output is correct
2 Correct 14 ms 27704 KB Output is correct
3 Correct 13 ms 27628 KB Output is correct
4 Correct 14 ms 27648 KB Output is correct
5 Correct 15 ms 27720 KB Output is correct
6 Correct 13 ms 27604 KB Output is correct
7 Correct 16 ms 27672 KB Output is correct
8 Correct 13 ms 27692 KB Output is correct
9 Correct 14 ms 27732 KB Output is correct
10 Correct 14 ms 27652 KB Output is correct
11 Correct 13 ms 27744 KB Output is correct
12 Correct 14 ms 27664 KB Output is correct
13 Correct 15 ms 27732 KB Output is correct
14 Correct 14 ms 27728 KB Output is correct
15 Correct 14 ms 27732 KB Output is correct
16 Correct 13 ms 27732 KB Output is correct
17 Correct 14 ms 27732 KB Output is correct
18 Correct 13 ms 27660 KB Output is correct
19 Correct 15 ms 27660 KB Output is correct
20 Correct 37 ms 27860 KB Output is correct
21 Correct 14 ms 27724 KB Output is correct
22 Correct 14 ms 27732 KB Output is correct
23 Correct 14 ms 27792 KB Output is correct
24 Correct 14 ms 27732 KB Output is correct
25 Correct 14 ms 27712 KB Output is correct
26 Correct 14 ms 27788 KB Output is correct
27 Correct 15 ms 27732 KB Output is correct
28 Correct 14 ms 27732 KB Output is correct
29 Correct 15 ms 27788 KB Output is correct
30 Correct 17 ms 27772 KB Output is correct
31 Correct 14 ms 27836 KB Output is correct
32 Correct 14 ms 27732 KB Output is correct
33 Correct 18 ms 27800 KB Output is correct
34 Correct 17 ms 27860 KB Output is correct
35 Correct 18 ms 28432 KB Output is correct
36 Correct 17 ms 27772 KB Output is correct
37 Correct 17 ms 28312 KB Output is correct
38 Correct 22 ms 28524 KB Output is correct
39 Correct 24 ms 28368 KB Output is correct
40 Correct 18 ms 28500 KB Output is correct
41 Correct 22 ms 28528 KB Output is correct
42 Correct 17 ms 28372 KB Output is correct
43 Correct 18 ms 28360 KB Output is correct
44 Correct 383 ms 28404 KB Output is correct
45 Correct 22 ms 28500 KB Output is correct
46 Correct 21 ms 28500 KB Output is correct
47 Correct 21 ms 29036 KB Output is correct
48 Correct 18 ms 28548 KB Output is correct
49 Correct 18 ms 28560 KB Output is correct
50 Correct 18 ms 28364 KB Output is correct
51 Correct 28 ms 29960 KB Output is correct
52 Correct 28 ms 29460 KB Output is correct
53 Correct 25 ms 29160 KB Output is correct
54 Correct 14 ms 27860 KB Output is correct
55 Correct 16 ms 27868 KB Output is correct
56 Execution timed out 1084 ms 29528 KB Time limit exceeded
57 Halted 0 ms 0 KB -