Submission #563143

# Submission time Handle Problem Language Result Execution time Memory
563143 2022-05-16T11:27:42 Z piOOE Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
140 ms 262144 KB
//#define _GLIBCXX_DEBUG

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//
//using namespace __gnu_pbds;
//
//template<typename T>
//using ordered_set = tree<T, null_type, less < T>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define trace(x) cout << #x << ": " << (x) << endl;
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define uniq(x) x.resize(unique(all(x)) - begin(x))
#define sz(s) ((int) size(s))
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
#define int128 __int128
#define pb push_back
#define popb pop_back
#define eb emplace_back
#define fi first
#define se second
#define itn int

typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;


template<typename T>
bool ckmn(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool ckmx(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

int bit(int x, int b) {
    return (x >> b) & 1;
}

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }


const ll infL = 3e18;
const int infI = 1000000000 + 7;
const int infM = 0x3f3f3f3f; //a little bigger than 1e9
const ll infML = 0x3f3f3f3f3f3f3f3fLL; //4.5e18
const int N = 30002, B = 2000;
const int mod = 998244353;
const ld eps = 1e-9;

int dist[B][N], S[N], P[N];
bool used[B][N];
vector<array<int, 3>> adj[B][N];


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> S[i] >> P[i];
        if (P[i] < B) {
            adj[0][S[i]].push_back({0, P[i], S[i]});
        } else {
            for (int w = 1; P[i] * w + S[i] < n; ++w) {
                adj[0][S[i]].push_back({w, 0, P[i] * w + S[i]});
            }
            for (int w = -1; P[i] * w + S[i] > -1; --w) {
                adj[0][S[i]].push_back({-w, 0, P[i] * w + S[i]});
            }
        }
    }
    priority_queue<array<int, 3>> pq;
    auto add = [&pq] (int w, int i, int j) {
        if (dist[i][j] > w) {
            dist[i][j] = w;
            pq.push({w, i, j});
        }
    };
    memset(dist, 0x3f, sizeof(dist));
    add(0, 0, S[0]);
    while (!pq.empty()) {
        auto[ww, i, j] = pq.top();
        pq.pop();
        if (used[i][j]) {
            continue;
        }
        used[i][j] = true;
        if (j == S[1]) {
            cout << ww;
            return 0;
        }
        for (auto t : adj[i][j]) {
            add(t[0] + dist[i][j], t[1], t[2]);
        }
        if (i) {
            add(dist[i][j], 0, j);
        }
        if (i + j < n) {
            add(dist[i][j] + 1, i, i + j);
        }
        if (j - i > -1) {
            add(dist[i][j] + 1, i, j - i);
        }
    }
    cout << -1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 140 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 125 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -