답안 #887009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887009 2023-12-13T12:30:15 Z Mher777 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
629 ms 3788 KB
/* ----------------------------- Mher777 ----------------------------- */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
#include <cassert>
using namespace std;

/* -------------------- Typedefs -------------------- */

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef float fl;
typedef double db;
typedef long double ld;

/* -------------------- Usings -------------------- */

using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* -------------------- Defines -------------------- */

#define kap map
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) (x).begin(), (x).end()

/* -------------------- Constants -------------------- */

const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);
const ll CON = (ll)(911382323);
const ll MOD3 = (ll)(972663749);

/* -------------------- Functions -------------------- */

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void precision(int x) {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(x);
}

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll range_sum(ll a, ll b) {
    ll dif = a - 1, cnt = b - a + 1;
    ll ans = ((b - a + 1) * (b - a + 2)) / 2;
    ans += ((b - a + 1) * dif);
    return ans;
}

string dec_to_bin(ll a) {
    string s = "";
    for (ll i = a; i > 0; ) {
        ll k = i % 2;
        i /= 2;
        char c = k + 48;
        s += c;
    }
    if (a == 0) {
        s = "0";
    }
    reverse(all(s));
    return s;
}

ll bin_to_dec(string s) {
    ll num = 0;
    for (int i = 0; i < s.size(); i++) {
        num *= 2ll;
        num += (s[i] - '0');
    }
    return num;
}

int isPrime(ll a) {
    if (a == 1) return 0;
    for (ll i = 2; i * i <= a; i++) {
        if (a % i == 0) return 0;
    }
    return 1;
}

ll binpow(ll a, ll b) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
        }
        b >>= 1;
        a *= a;
    }
    return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= mod;
        }
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return ans;
}

/* -------------------- Solution -------------------- */

const int N = 30005;
vi g[N];
map<pii, int> used;

void slv() {
    int n, m;
    cin >> n >> m;
    int s = 0, t = 0;
    for (int i = 0; i < m; ++i) {
        int x, p;
        cin >> x >> p;
        if (i == 0) s = x;
        if (i == 1) t = x;
        g[x].pub(p);
    }
    vi d(n + 1, MAX), used(n + 1);
    priority_queue<pii> pq;
    d[s] = 0;
    pq.push({ 0, s });
    while (!pq.empty()) {
        int u = pq.top().ss, len = -pq.top().ff;
        pq.pop();
        if (used[u]) continue;
        used[u] = 1;
        for (auto elem : g[u]) {
            int dist = 0;
            for (int i = u; i < n; i += elem) {
                if (d[u] + dist < d[i]) {
                    d[i] = d[u] + dist;
                    pq.push({ -d[i],i });
                }
                ++dist;
            }
            dist = 0;
            for (int i = u; i >= 0; i -= elem) {
                if (d[u] + dist < d[i]) {
                    d[i] = d[u] + dist;
                    pq.push({ -d[i],i });
                }
                ++dist;
            }
        }
    }
    cout << (d[t] == MAX ? -1 : d[t]);
}

void cs() {
    int tstc = 1;
    //cin >> tstc;
    while (tstc--) {
        slv();
    }
}

void precalc() {
    return;
}

int main() {
    fastio();
    precalc();
    //precision(0);
    cs();
    return 0;
}

Compilation message

skyscraper.cpp: In function 'll range_sum(ll, ll)':
skyscraper.cpp:95:21: warning: unused variable 'cnt' [-Wunused-variable]
   95 |     ll dif = a - 1, cnt = b - a + 1;
      |                     ^~~
skyscraper.cpp: In function 'll bin_to_dec(std::string)':
skyscraper.cpp:118:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
skyscraper.cpp: In function 'void slv()':
skyscraper.cpp:183:30: warning: unused variable 'len' [-Wunused-variable]
  183 |         int u = pq.top().ss, len = -pq.top().ff;
      |                              ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1160 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1112 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1112 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1164 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1188 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1112 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1112 KB Output is correct
17 Correct 1 ms 1112 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1172 KB Output is correct
23 Correct 1 ms 1116 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 2 ms 1640 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 4 ms 1112 KB Output is correct
28 Correct 1 ms 1116 KB Output is correct
29 Correct 1 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1112 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 912 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 1 ms 1116 KB Output is correct
15 Correct 1 ms 1116 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 4 ms 1116 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1168 KB Output is correct
23 Correct 1 ms 1112 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1168 KB Output is correct
26 Correct 3 ms 1116 KB Output is correct
27 Correct 5 ms 1116 KB Output is correct
28 Correct 1 ms 1128 KB Output is correct
29 Correct 1 ms 1112 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1116 KB Output is correct
34 Correct 2 ms 1372 KB Output is correct
35 Correct 5 ms 1628 KB Output is correct
36 Correct 2 ms 1116 KB Output is correct
37 Correct 4 ms 1624 KB Output is correct
38 Correct 6 ms 1656 KB Output is correct
39 Correct 6 ms 1628 KB Output is correct
40 Correct 6 ms 1624 KB Output is correct
41 Correct 6 ms 1568 KB Output is correct
42 Correct 41 ms 1372 KB Output is correct
43 Correct 41 ms 1372 KB Output is correct
44 Correct 42 ms 1372 KB Output is correct
45 Correct 5 ms 1624 KB Output is correct
46 Correct 5 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 1120 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1160 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1192 KB Output is correct
13 Correct 1 ms 1120 KB Output is correct
14 Correct 1 ms 1120 KB Output is correct
15 Correct 1 ms 1120 KB Output is correct
16 Correct 1 ms 1120 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 1 ms 1172 KB Output is correct
19 Correct 1 ms 1120 KB Output is correct
20 Correct 4 ms 1120 KB Output is correct
21 Correct 1 ms 1116 KB Output is correct
22 Correct 1 ms 1120 KB Output is correct
23 Correct 1 ms 1120 KB Output is correct
24 Correct 1 ms 1116 KB Output is correct
25 Correct 1 ms 1116 KB Output is correct
26 Correct 3 ms 1172 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 1 ms 1244 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1116 KB Output is correct
32 Correct 1 ms 1116 KB Output is correct
33 Correct 2 ms 1116 KB Output is correct
34 Correct 2 ms 1168 KB Output is correct
35 Correct 5 ms 1628 KB Output is correct
36 Correct 2 ms 1176 KB Output is correct
37 Correct 4 ms 1628 KB Output is correct
38 Correct 6 ms 1628 KB Output is correct
39 Correct 6 ms 1712 KB Output is correct
40 Correct 6 ms 1712 KB Output is correct
41 Correct 6 ms 1628 KB Output is correct
42 Correct 42 ms 1596 KB Output is correct
43 Correct 41 ms 1368 KB Output is correct
44 Correct 41 ms 1372 KB Output is correct
45 Correct 5 ms 1624 KB Output is correct
46 Correct 5 ms 1628 KB Output is correct
47 Correct 12 ms 2264 KB Output is correct
48 Correct 4 ms 1884 KB Output is correct
49 Correct 5 ms 1936 KB Output is correct
50 Correct 3 ms 1812 KB Output is correct
51 Correct 19 ms 3392 KB Output is correct
52 Correct 18 ms 2776 KB Output is correct
53 Correct 10 ms 2796 KB Output is correct
54 Correct 2 ms 1628 KB Output is correct
55 Correct 2 ms 1420 KB Output is correct
56 Correct 619 ms 2908 KB Output is correct
57 Correct 36 ms 3532 KB Output is correct
58 Correct 629 ms 1884 KB Output is correct
59 Correct 574 ms 1880 KB Output is correct
60 Correct 603 ms 1884 KB Output is correct
61 Correct 519 ms 1880 KB Output is correct
62 Correct 7 ms 2648 KB Output is correct
63 Correct 18 ms 3028 KB Output is correct
64 Correct 18 ms 2772 KB Output is correct
65 Correct 20 ms 3028 KB Output is correct
66 Correct 33 ms 3788 KB Output is correct
67 Correct 28 ms 3788 KB Output is correct