Submission #554463

# Submission time Handle Problem Language Result Execution time Memory
554463 2022-04-28T12:41:02 Z SmolBrain Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
163 ms 9732 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, i});
    }

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

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

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

        if (id == 1) {
            cout << cost << endl;
            return;
        }

        int p = a[id].ss;

        // if (b < n) {
        //     dummy[b].pb({b + n, 0});
        //     dummy[b + n].pb({b, id});
        // }

        // edges with weight = 0
        for (auto [b2, id2] : dummy[b]) {
            dq.push_front({cost, b2, id2});
        }

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

    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 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 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 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 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 372 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 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 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 340 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 596 KB Output is correct
20 Correct 113 ms 8392 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 4 ms 6740 KB Output is correct
24 Correct 6 ms 7892 KB Output is correct
25 Correct 3 ms 3104 KB Output is correct
26 Correct 6 ms 8276 KB Output is correct
27 Correct 6 ms 8372 KB Output is correct
28 Correct 8 ms 8308 KB Output is correct
29 Correct 8 ms 8376 KB Output is correct
30 Correct 7 ms 8276 KB Output is correct
31 Correct 7 ms 8276 KB Output is correct
32 Correct 6 ms 8364 KB Output is correct
33 Correct 11 ms 8344 KB Output is correct
34 Correct 9 ms 8500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 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 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 2 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 340 KB Output is correct
17 Correct 2 ms 3284 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 107 ms 8460 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 6668 KB Output is correct
24 Correct 7 ms 7988 KB Output is correct
25 Correct 3 ms 3120 KB Output is correct
26 Correct 6 ms 8276 KB Output is correct
27 Correct 7 ms 8404 KB Output is correct
28 Correct 8 ms 8360 KB Output is correct
29 Correct 11 ms 8276 KB Output is correct
30 Correct 7 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 10 ms 8404 KB Output is correct
34 Correct 7 ms 8396 KB Output is correct
35 Correct 10 ms 7128 KB Output is correct
36 Correct 3 ms 2900 KB Output is correct
37 Correct 9 ms 8532 KB Output is correct
38 Correct 10 ms 7996 KB Output is correct
39 Correct 7 ms 1876 KB Output is correct
40 Correct 11 ms 5396 KB Output is correct
41 Correct 9 ms 6548 KB Output is correct
42 Correct 10 ms 9132 KB Output is correct
43 Correct 13 ms 9732 KB Output is correct
44 Incorrect 163 ms 9496 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 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 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 348 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 852 KB Output is correct
13 Correct 2 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 340 KB Output is correct
17 Correct 2 ms 3284 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 111 ms 8400 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 6740 KB Output is correct
24 Correct 5 ms 7892 KB Output is correct
25 Correct 3 ms 3124 KB Output is correct
26 Correct 5 ms 8276 KB Output is correct
27 Correct 7 ms 8404 KB Output is correct
28 Correct 7 ms 8404 KB Output is correct
29 Correct 8 ms 8276 KB Output is correct
30 Correct 6 ms 8276 KB Output is correct
31 Correct 7 ms 8360 KB Output is correct
32 Correct 6 ms 8364 KB Output is correct
33 Correct 10 ms 8368 KB Output is correct
34 Correct 7 ms 8372 KB Output is correct
35 Correct 13 ms 7160 KB Output is correct
36 Correct 3 ms 2872 KB Output is correct
37 Correct 9 ms 8532 KB Output is correct
38 Correct 11 ms 7964 KB Output is correct
39 Correct 7 ms 1876 KB Output is correct
40 Correct 9 ms 5432 KB Output is correct
41 Correct 10 ms 6612 KB Output is correct
42 Correct 10 ms 9040 KB Output is correct
43 Correct 12 ms 9680 KB Output is correct
44 Incorrect 162 ms 9428 KB Output isn't correct
45 Halted 0 ms 0 KB -