제출 #52663

#제출 시각아이디문제언어결과실행 시간메모리
52663evpipisJakarta Skyscrapers (APIO15_skyscraper)C++11
57 / 100
1080 ms65140 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;

const int len = 30005, inf = 1e9;
int po[len], pos[len], vis[len];
vector<int> vec[len];
unordered_map<int, int> mymap[len];
deque<pair<int, ii> > deq;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++)
        scanf("%d %d", &pos[i], &po[i]);
    for (int i = 0; i < m; i++)
        vec[pos[i]].pb(po[i]);

    int ans = -1;
    deq.pb(mp(0, mp(pos[0], po[0])));
    while (!deq.empty()){
        pair<int, ii> top = deq.front();
        deq.pop_front();

        int d = top.fi, b = top.se.fi, p = top.se.se;
        if (b == pos[1]){
            ans = d;
            break;
        }

        if (mymap[b].count(p)) continue;
        mymap[b][p] = d;
        if (b+p < n)
            deq.pb(mp(d+1, mp(b+p, p)));
        if (b-p >= 0)
            deq.pb(mp(d+1, mp(b-p, p)));

        if (vis[b]) continue;
        vis[b] = 1;
        for (int j = 0; j < vec[b].size(); j++)
            deq.push_front(mp(d, mp(b, vec[b][j])));
    }

    printf("%d\n", ans);
    return 0;
}

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

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:45:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[b].size(); j++)
                         ~~^~~~~~~~~~~~~~~
skyscraper.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &pos[i], &po[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...