Submission #554470

# Submission time Handle Problem Language Result Execution time Memory
554470 2022-04-28T12:54:52 Z SmolBrain Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
34 ms 9856 KB
// Om Namah Shivaya
// GM in 96 days

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define endl '\n'
#define pb push_back
#define conts continue
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ff first
#define ss second
#define ceil2(x,y) ((x+y-1) / (y))
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#ifndef ONLINE_JUDGE
#define debug(x) cout << #x <<" = "; print(x); cout << endl
#else
#define debug(x)
#endif

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

bool iseven(ll n) {if ((n & 1) == 0) return true; return false;}

void print(ll t) {cout << t;}
void print(int t) {cout << t;}
void print(string t) {cout << t;}
void print(char t) {cout << t;}
void print(double t) {cout << t;}
void print(ld t) {cout << t;}

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(pair <T, V> p) {cout << "{"; print(p.ff); cout << ","; print(p.ss); cout << "}";}
template <class T> void print(vector <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(set <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T> void print(multiset <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";}
template <class T, class V> void print(map <T, V> v) {cout << "[ "; for (auto i : v) {print(i); cout << " ";} cout << "]";}
template<typename T> void amin(T &a, T b) { a = min(a, b); }
template<typename T> void amax(T &a, T b) { a = max(a, b); }

void usaco(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const int maxn = 2005;
const int inf1 = 1e9 + 5;
const ll inf2 = ll(1e18) + 5;

vector<pii> dummy[maxn * 2];
bool vis[maxn * 2][maxn];

void solve(int test_case)
{
    // editorial approach
    int n, m; cin >> n >> m;
    vector<pii> a(m);

    rep(i, n) dummy[i].pb({i + n, 0});

    rep(i, m) {
        int b, p; cin >> b >> p;
        a[i] = {b, p};

        // b + n = dummy vertex
        dummy[b + n].pb({b, p});
    }

    deque<array<int, 3>> dq;
    dq.pb({0, a[0].ff, a[0].ss});

    while (!dq.empty()) {
        auto [cost, b, p] = dq.front();
        dq.pop_front();

        if (vis[b][p]) conts;
        vis[b][p] = 1;

        if (b == a[1].ff and p == a[1].ss) {
            cout << cost << endl;
            return;
        }

        // edges with weight = 0
        if (b < n) {
            dq.push_front({cost, b + n, 0});
        }

        for (auto [b2, p2] : dummy[b]) {
            dq.push_front({cost, b2, p2});
        }

        // edges with weight = 1
        if (b < n) {
            if (b + p < n) dq.pb({cost + 1, b + p, p});
            if (b - p >= 0) dq.pb({cost + 1, b - p, p});
        }
    }

    cout << -1 << endl;
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;
    rep1(i, t) {
        solve(i);
    }

    return 0;
}

Compilation message

skyscraper.cpp: In function 'void usaco(std::string)':
skyscraper.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 416 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 420 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 812 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 2 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 552 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 816 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 2 ms 852 KB Output is correct
15 Correct 2 ms 820 KB Output is correct
16 Correct 1 ms 420 KB Output is correct
17 Correct 3 ms 3252 KB Output is correct
18 Correct 1 ms 428 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 5 ms 6708 KB Output is correct
24 Correct 6 ms 7864 KB Output is correct
25 Correct 2 ms 3028 KB Output is correct
26 Correct 5 ms 8276 KB Output is correct
27 Correct 6 ms 8376 KB Output is correct
28 Correct 8 ms 8308 KB Output is correct
29 Correct 8 ms 8276 KB Output is correct
30 Correct 6 ms 8232 KB Output is correct
31 Correct 7 ms 8276 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 11 ms 8344 KB Output is correct
34 Correct 8 ms 8404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 424 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 424 KB Output is correct
7 Correct 1 ms 420 KB Output is correct
8 Correct 1 ms 420 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 432 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 812 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 428 KB Output is correct
17 Correct 3 ms 3284 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 556 KB Output is correct
20 Correct 6 ms 8404 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 5 ms 6868 KB Output is correct
24 Correct 6 ms 7892 KB Output is correct
25 Correct 3 ms 3124 KB Output is correct
26 Correct 6 ms 8276 KB Output is correct
27 Correct 6 ms 8404 KB Output is correct
28 Correct 9 ms 8404 KB Output is correct
29 Correct 9 ms 8352 KB Output is correct
30 Correct 8 ms 8420 KB Output is correct
31 Correct 7 ms 8276 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 11 ms 8340 KB Output is correct
34 Correct 9 ms 8404 KB Output is correct
35 Correct 11 ms 7136 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 10 ms 8268 KB Output is correct
38 Correct 10 ms 7176 KB Output is correct
39 Correct 6 ms 1516 KB Output is correct
40 Correct 8 ms 3452 KB Output is correct
41 Correct 8 ms 4692 KB Output is correct
42 Correct 10 ms 9040 KB Output is correct
43 Correct 10 ms 9296 KB Output is correct
44 Correct 10 ms 9392 KB Output is correct
45 Correct 32 ms 9816 KB Output is correct
46 Correct 20 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 428 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 424 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 552 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 3284 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 556 KB Output is correct
20 Correct 5 ms 8408 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 428 KB Output is correct
23 Correct 5 ms 6676 KB Output is correct
24 Correct 6 ms 7892 KB Output is correct
25 Correct 2 ms 3028 KB Output is correct
26 Correct 5 ms 8276 KB Output is correct
27 Correct 5 ms 8404 KB Output is correct
28 Correct 7 ms 8360 KB Output is correct
29 Correct 8 ms 8276 KB Output is correct
30 Correct 8 ms 8276 KB Output is correct
31 Correct 7 ms 8276 KB Output is correct
32 Correct 6 ms 8276 KB Output is correct
33 Correct 11 ms 8364 KB Output is correct
34 Correct 12 ms 8324 KB Output is correct
35 Correct 12 ms 7100 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 10 ms 8296 KB Output is correct
38 Correct 10 ms 7096 KB Output is correct
39 Correct 6 ms 1492 KB Output is correct
40 Correct 7 ms 3476 KB Output is correct
41 Correct 8 ms 4636 KB Output is correct
42 Correct 9 ms 9048 KB Output is correct
43 Correct 10 ms 9288 KB Output is correct
44 Correct 12 ms 9296 KB Output is correct
45 Correct 34 ms 9856 KB Output is correct
46 Correct 23 ms 9808 KB Output is correct
47 Runtime error 2 ms 1364 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -