제출 #1162202

#제출 시각아이디문제언어결과실행 시간메모리
1162202minhpkJakarta Skyscrapers (APIO15_skyscraper)C++17
컴파일 에러
0 ms0 KiB
#include "bits/stdc++.h"
using namespace std;

const int MAX_POS = 300005;
const int MAX_TYPE = 3005;
const long long INF = 1e18;

int a, b;
vector<int> z[MAX_POS];
int blocksize;
pair<int, int> mark[30005];

struct node {
    int val, pos, type;
    bool operator>(const node &other) const {
        return val > other.val;
    }
};

static long long dp[MAX_POS][MAX_TYPE];

void dijkstra() {
    for (int i = 0; i < a; i++) {
        for (int t = 0; t < MAX_TYPE; t++) {
            dp[i][t] = INF;
        }
    }
    int startPos = mark[0].first, startType = mark[0].second;
    dp[startPos][startType] = 0;
    priority_queue<node, vector<node>, greater<node>> pq;
    pq.push({0, startPos, startType});
    while (!pq.empty()) {
        node cur = pq.top();
        pq.pop();
        int d = cur.val, pos = cur.pos, type = cur.type;
        if (dp[pos][type] < d) continue;
        if (type == 0) {
            for (int p : z[pos]) {
                int newPos = pos + p;
                if (newPos < a && p < MAX_TYPE) {
                    if (dp[newPos][p] > d + 1) {
                        dp[newPos][p] = d + 1;
                        pq.push({d + 1, newPos, p});
                    }
                }
                newPos = pos - p;
                if (newPos >= 0 && p < MAX_TYPE) {
                    if (dp[newPos][p] > d + 1) {
                        dp[newPos][p] = d + 1;
                        pq.push({d + 1, newPos, p});
                    }
                }
            }
        } else {
            if (dp[pos][0] > d) {
                dp[pos][0] = d;
                pq.push({d, pos, 0});
            }
            if (type > blocksize) {
                for (int step = 1; pos + step * type < a; step++) {
                    int newPos = pos + step * type;
                    if (dp[newPos][0] > d + step) {
                        dp[newPos][0] = d + step;
                        pq.push({d + step, newPos, 0});
                    }
                }
                for (int step = 1; pos - step * type >= 0; step++) {
                    int newPos = pos - step * type;
                    if (dp[newPos][0] > d + step) {
                        dp[newPos][0] = d + step;
                        pq.push({d + step, newPos, 0});
                    }
                }
            } else {
                int newPos = pos + type;
                if (newPos < a && type < MAX_TYPE) {
                    if (dp[newPos][type] > d + 1) {
                        dp[newPos][type] = d + 1;
                        pq.push({d + 1, newPos, type});
                    }
                }
                newPos = pos - type;
                if (newPos >= 0 && type < MAX_TYPE) {
                    if (dp[newPos][type] > d + 1) {
                        dp[newPos][type] = d + 1;
                        pq.push({d + 1, newPos, type});
                    }
                }
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> a >> b;
    blocksize = sqrt(a);
    for (int i = 0; i < b; i++){
        int x, y;
        cin >> x >> y;
        z[x].push_back(y);
        mark[i] = {x, y};
    }
    if (b == 0) {
        cout << -1;
        return 0;
    }
    dijkstra();
    int finalPos = mark[1].first;
    if (dp[finalPos][0] < INF)
        cout << dp[finalPos][0];
    else
        cout << -1;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

/tmp/ccxJCl5T.o: in function `main':
skyscraper.cpp:(.text.startup+0x12): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
skyscraper.cpp:(.text.startup+0x3d): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
skyscraper.cpp:(.text.startup+0x159): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
skyscraper.cpp:(.text.startup+0x186): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
/tmp/ccxJCl5T.o: in function `_GLOBAL__sub_I_a':
skyscraper.cpp:(.text.startup+0x1b1): relocation truncated to fit: R_X86_64_PC32 against `.bss'
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(vterminate.o): in function `__gnu_cxx::__verbose_terminate_handler()':
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x1e): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
(.text._ZN9__gnu_cxx27__verbose_terminate_handlerEv+0x2b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZZN9__gnu_cxx27__verbose_terminate_handlerEvE11terminating'
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1c): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x60): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x67): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x72): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_internal::buf_cout_sync' defined in .bss._ZN14__gnu_internal13buf_cout_syncE section in /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(globals_io.o)
(.text._ZNSt8ios_base4InitC2Ev+0x87): additional relocation overflows omitted from the output
(.text._ZNSt8ios_base4InitC2Ev+0x1c6): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x260): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2e2): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x353): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x541): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5e5): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x670): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x6e9): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
collect2: error: ld returned 1 exit status