답안 #971302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971302 2024-04-28T11:03:44 Z LOLOLO Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1 ms 388 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 1e5 + 10;
int d[N], p[N], used[N];

ll solve() {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> p[i] >> d[i];
    }

    priority_queue <pair <int, int>, vector <pair <int, int>>, greater <pair <int, int>>> pq;

    for (int i = 0; i < m; i++) {
        if (abs(p[i] - p[1]) % d[i] == 0) {
            pq.push({abs(p[i] - p[1]) / d[i], i});
        }
    }

    used[1] = 1;
    ll all = 0;
    while (sz(pq)) {
        auto t = pq.top();
        pq.pop();

        if (used[t.s]) 
            continue;

        all += t.f;
        used[t.s] = 1;
        for (int i = 0; i < m; i++) {
            if (abs(p[i] - p[t.s]) % d[i] == 0 && used[i] == 0) {
                pq.push({abs(p[i] - p[t.s]) / d[i], i});
            }
        }
    }

    return all;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    cout.tie(0);

    cout << solve() << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 388 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -