Submission #1004778

# Submission time Handle Problem Language Result Execution time Memory
1004778 2024-06-21T14:44:04 Z codexistent Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
2 ms 1368 KB
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define FOR(i, a, b) for(long long i = a; i <= b; i++)
#define MAXN 30005
 
long long n, m, t[MAXN], s, e;
vector<long long> p[MAXN];
set<long long> a;
 
int main(){
    cin >> n >> m;
    FOR(i, 0, n - 1) t[i] = -1;
    FOR(i, 0, m - 1){
        int b, pi; cin >> b >> pi;
        if(i == 0) s = b, t[b] = 0;
        if(i == 1) e = b;
        p[b].push_back(pi);
    }
    FOR(i, 0, n - 1) if(i != s) a.insert(i);
    
    long long c = s;
    pair<long long, long long> nx = make_pair(-1, -1);
    while(c != -1){
        for(long long i : a){
            for(long long j : p[c]){
                if(abs(i - c) % j == 0){
                    t[i] = (t[i] == -1) ? (t[c] + abs(i - c) / j) : min(t[i], t[c] + abs(i - c) / j);
                }
            }
            
          if(nx.first == -1 || (t[i] != -1 && nx.first > t[i])){
            nx.first = t[i];
                nx.second = i;
          }
        }
        
        a.erase(c);
        c = nx.second;
        nx.first = nx.second = -1;
    }
    
    cout << t[e] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1116 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 2 ms 1116 KB Output is correct
12 Correct 1 ms 1112 KB Output is correct
13 Correct 1 ms 1368 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 0 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Incorrect 1 ms 1140 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 0 ms 1116 KB Output is correct
3 Correct 1 ms 1116 KB Output is correct
4 Correct 0 ms 1116 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 0 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 1116 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 1 ms 1120 KB Output is correct
11 Correct 2 ms 1200 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1116 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Incorrect 2 ms 1120 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1116 KB Output is correct
2 Correct 1 ms 1120 KB Output is correct
3 Correct 0 ms 1116 KB Output is correct
4 Correct 0 ms 1120 KB Output is correct
5 Correct 1 ms 1112 KB Output is correct
6 Correct 0 ms 1120 KB Output is correct
7 Correct 0 ms 1116 KB Output is correct
8 Correct 0 ms 1116 KB Output is correct
9 Correct 0 ms 1116 KB Output is correct
10 Correct 1 ms 1116 KB Output is correct
11 Correct 1 ms 1116 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 KB Output is correct
14 Correct 2 ms 1192 KB Output is correct
15 Correct 2 ms 1116 KB Output is correct
16 Incorrect 1 ms 1116 KB Output isn't correct
17 Halted 0 ms 0 KB -