Submission #166845

# Submission time Handle Problem Language Result Execution time Memory
166845 2019-12-04T10:20:22 Z Hideo Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
179 ms 164924 KB
// Need to git gud and reach 1900+
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define prev prev123
#define next next123
#define pow pow123
#define left left123
#define right right123

const int N = 30007;
const int M = 6e6 + 7;
const int INF = 1e9 + 7;

pi a[N];
int d[M];
int m, n;

vector < pi > g[M];

main(){ // If you don't know what to do, check the text box at the bottom
    cin >> m >> n;
    for (int i = 1; i <= n; i++){
        scanf("%d%d", &a[i].fr, &a[i].sc);
        a[i].fr++;
    }
    sort(a + 1, a + n + 1);
    int k = unique(a + 1, a + n + 1) - a;
    for (int i = 1; i < k; i++){
        if (a[i].sc <= 175)
            g[a[i].fr].pb(mk(m + (a[i].fr - 1) * 175 + a[i].sc, 0));
        else {
            int pos = a[i].fr, pw = a[i].sc, c = 0;
            while (pos + pw <= m){
                pos += pw; c++;
                g[a[i].fr].pb(mk(pos, c));
            }
            pos = a[i].fr, c = 0;
            while (pos - pw > 0){
                pos -= pw; c++;
                g[a[i].fr].pb(mk(pos, c));
            }
        }
    }
    for (int i = 1; i <= m; i++){
        for (int j = 1; j <= 175; j++){
            if (i + j <= m){
                g[m + (i - 1) * 175 + j].pb(mk(m + (i + j - 1) * 175 + j, 1));
                g[m + (i - 1) * 175 + j].pb(mk(i + j, 1));
            }
            if (i - j > 0){
                g[m + (i - 1) * 175 + j].pb(mk(m + (i - j - 1) * 175 + j, 1));
                g[m + (i - 1) * 175 + j].pb(mk(i - j, 1));
            }
        }
    }
    priority_queue < pi > pq;
    pq.push(mk(0, a[1].fr));
    memset(d, 0x3f3f3f3f, sizeof(d));
    d[a[1].fr] = 0;
    while (!pq.empty()){
        int w = -pq.top().fr, v = pq.top().sc;
        pq.pop();
        if (d[v] < w)
            continue;
        for (pi to : g[v]){
            if (d[to.fr] > d[v] + to.sc){
                d[to.fr] = d[v] + to.sc;
                pq.push(mk(-d[to.fr], to.fr));
            }
        }
    }
    cout << d[a[2].fr];
}

/*
    Totally not inspired by BenQ's template
    Things you should do:
    1. Look for stupid typos in code e.g 1 instead of -1 etc
    2. Check if there is no infinite loops
    3. "Measure twice, cut once"
    4. Stay focused
*/

Compilation message

skyscraper.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){ // If you don't know what to do, check the text box at the bottom
      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].fr, &a[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 175 ms 164728 KB Output is correct
2 Correct 179 ms 164748 KB Output is correct
3 Incorrect 177 ms 164856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 177 ms 164708 KB Output is correct
2 Correct 176 ms 164728 KB Output is correct
3 Incorrect 178 ms 164728 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 164836 KB Output is correct
2 Correct 177 ms 164828 KB Output is correct
3 Incorrect 176 ms 164848 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 164692 KB Output is correct
2 Correct 176 ms 164740 KB Output is correct
3 Incorrect 176 ms 164924 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 178 ms 164728 KB Output is correct
2 Correct 177 ms 164700 KB Output is correct
3 Incorrect 177 ms 164644 KB Output isn't correct
4 Halted 0 ms 0 KB -