답안 #695159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
695159 2023-02-04T18:50:21 Z Farhan_HY Jakarta Skyscrapers (APIO15_skyscraper) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define int long long
#define float double
#define pb push_back
#define F first
#define S second
#define T int t; cin >> t; while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
/// Benzema is the best player in the world
const int N = 1e6 + 6;
const int M = 1e3 + 3;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int LOG = 28;
int n, m;
int p[N], dist[N];
vector<pair<int, int>> adj[N];
priority_queue<pair<int, int>> q;
bool vis[N];

void dij() {
    for(int i = 1; i <= n; i++) dist[i] = inf;
    q.push({b[1], 1});
    dist[b[1]] = 0;
    while(!q.empty()) {
        int u = q.top().S;
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        for(auto x: adj[u]) {
            if (dist[x.F] > dist[u] + x.S)
                dist[x.F] = dist[u] + x.S, q.push({-dist[x.F], x.F});
        }
    }
}

int b[N];
main() {
    IOS
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        cin >> b[i] >> p[i];
        b[i]++;
        int j = b[i] - p[i], cnt = 1;
        while(j >= 1) {
            adj[b[i]].push_back({j, cnt++});
            j -= p[i];
        }
        cnt = 1, j = b[i] + p[i];
        while(j <= n) {
            adj[b[i]].push_back({j, cnt++});
            j += p[i];
        }
    }
    dij();
    if (dist[b[2]] == inf) dist[2] = -1;
    cout << dist[2];
}

Compilation message

skyscraper.cpp: In function 'void dij()':
skyscraper.cpp:27:13: error: 'b' was not declared in this scope
   27 |     q.push({b[1], 1});
      |             ^
skyscraper.cpp:27:21: error: no matching function for call to 'std::priority_queue<std::pair<long long int, long long int> >::push(<brace-enclosed initializer list>)'
   27 |     q.push({b[1], 1});
      |                     ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from skyscraper.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, long long int>]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::vector<std::pair<long long int, long long int> >; _Compare = std::less<std::pair<long long int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long long int, long long int>]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
skyscraper.cpp: At global scope:
skyscraper.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main() {
      | ^~~~