Submission #49494

# Submission time Handle Problem Language Result Execution time Memory
49494 2018-05-29T19:33:10 Z updown1 Jakarta Skyscrapers (APIO15_skyscraper) C++17
22 / 100
53 ms 6428 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define w cout
#define e "\n"
#define s <<" "<<
#define pb push_back
#define mp make_pair
#define a first
#define b second
/// 500,000,000
const int MAXN = 30000, INF = 1000000000000000000;
/// Global Variables
int N, M, dist[MAXN], B[MAXN], P[MAXN];
bool vis[MAXN];
vector<int> dogs[MAXN];
priority_queue<pair<int, int> > next1;

void go(int loc) {
    vis[loc] = true;
    For (i, 0, dogs[loc].size()) {
        int x = dogs[loc][i];
        for (int j=loc+P[x], add = 1; j<N; j+= P[x], add++) {
            dist[j] = min(dist[j], dist[loc]+add);
            next1.push(mp(j, dist[j]));
        }
        for (int j=loc-P[x], add = 1; j>= 0; j-= P[x], add++) {
            dist[j] = min(dist[j], dist[loc]+add);
            next1.push(mp(j, dist[j]));
        }
    }
}

main() {
    //ifstream cin("test.in");
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    ffi dist[i] = INF;
    ffj {
        cin >> B[j] >> P[j];
        dogs[B[j]].pb(j);
    }
    next1.push(mp(B[0], 0));
    dist[B[0]] = 0;
    while (!next1.empty()) {
        int i = next1.top().a; next1.pop();
        if (!vis[i]) go(i);
    }
    if (dist[B[1]] == INF) w<< -1<<e;
    else w<< dist[B[1]]<<e;
}

Compilation message

skyscraper.cpp: In function 'void go(ll)':
skyscraper.cpp:5:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define For(i, a, b) for(int i=a; i<b; i++)
skyscraper.cpp:26:10:
     For (i, 0, dogs[loc].size()) {
          ~~~~~~~~~~~~~~~~~~~~~~     
skyscraper.cpp:26:5: note: in expansion of macro 'For'
     For (i, 0, dogs[loc].size()) {
     ^~~
skyscraper.cpp: At global scope:
skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1128 KB Output is correct
3 Correct 3 ms 1128 KB Output is correct
4 Correct 4 ms 1188 KB Output is correct
5 Correct 3 ms 1244 KB Output is correct
6 Correct 3 ms 1288 KB Output is correct
7 Correct 4 ms 1288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1288 KB Output is correct
2 Correct 3 ms 1352 KB Output is correct
3 Correct 3 ms 1412 KB Output is correct
4 Correct 3 ms 1412 KB Output is correct
5 Correct 3 ms 1412 KB Output is correct
6 Correct 3 ms 1440 KB Output is correct
7 Correct 3 ms 1440 KB Output is correct
8 Correct 3 ms 1540 KB Output is correct
9 Correct 3 ms 1596 KB Output is correct
10 Correct 3 ms 1596 KB Output is correct
11 Correct 4 ms 1708 KB Output is correct
12 Correct 53 ms 5804 KB Output is correct
13 Correct 41 ms 5880 KB Output is correct
14 Correct 5 ms 5880 KB Output is correct
15 Correct 4 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5880 KB Output is correct
2 Correct 3 ms 5880 KB Output is correct
3 Correct 3 ms 5880 KB Output is correct
4 Correct 2 ms 5880 KB Output is correct
5 Correct 3 ms 5880 KB Output is correct
6 Correct 4 ms 5880 KB Output is correct
7 Correct 3 ms 5880 KB Output is correct
8 Correct 2 ms 5880 KB Output is correct
9 Correct 2 ms 5880 KB Output is correct
10 Correct 5 ms 5880 KB Output is correct
11 Correct 5 ms 5880 KB Output is correct
12 Correct 42 ms 6172 KB Output is correct
13 Correct 49 ms 6172 KB Output is correct
14 Correct 6 ms 6172 KB Output is correct
15 Correct 4 ms 6172 KB Output is correct
16 Correct 4 ms 6172 KB Output is correct
17 Incorrect 7 ms 6172 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6172 KB Output is correct
2 Correct 3 ms 6172 KB Output is correct
3 Correct 3 ms 6172 KB Output is correct
4 Correct 3 ms 6172 KB Output is correct
5 Correct 2 ms 6172 KB Output is correct
6 Correct 3 ms 6172 KB Output is correct
7 Correct 2 ms 6172 KB Output is correct
8 Correct 2 ms 6172 KB Output is correct
9 Correct 2 ms 6172 KB Output is correct
10 Correct 3 ms 6172 KB Output is correct
11 Correct 4 ms 6172 KB Output is correct
12 Correct 40 ms 6312 KB Output is correct
13 Correct 38 ms 6312 KB Output is correct
14 Correct 3 ms 6312 KB Output is correct
15 Correct 3 ms 6312 KB Output is correct
16 Correct 2 ms 6312 KB Output is correct
17 Incorrect 6 ms 6312 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6312 KB Output is correct
2 Correct 2 ms 6312 KB Output is correct
3 Correct 2 ms 6312 KB Output is correct
4 Correct 2 ms 6312 KB Output is correct
5 Correct 2 ms 6312 KB Output is correct
6 Correct 2 ms 6312 KB Output is correct
7 Correct 2 ms 6312 KB Output is correct
8 Correct 2 ms 6312 KB Output is correct
9 Correct 2 ms 6312 KB Output is correct
10 Correct 3 ms 6312 KB Output is correct
11 Correct 4 ms 6312 KB Output is correct
12 Correct 39 ms 6344 KB Output is correct
13 Correct 47 ms 6428 KB Output is correct
14 Correct 3 ms 6428 KB Output is correct
15 Correct 4 ms 6428 KB Output is correct
16 Correct 3 ms 6428 KB Output is correct
17 Incorrect 6 ms 6428 KB Output isn't correct
18 Halted 0 ms 0 KB -