답안 #1061252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061252 2024-08-16T07:30:50 Z 12345678 Reconstruction Project (JOI22_reconstruction) C++17
31 / 100
4288 ms 22844 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define int long long
#pragma gcc-optimize("o3, unroll-loops")

const int nx=5e2+5, mx=1e3+5;

ll n, m, a[mx], b[mx], w[mx], x, q, L[nx], R[nx], dsu[nx];
vector<ll> dp[nx];
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> add, rem;

int find(int x)
{
    if (dsu[x]==x) return x;
    return dsu[x]=find(dsu[x]);
}

bool isused(ll idx, ll cw)
{
    for (int i=1; i<=n; i++) dsu[i]=i;
    vector<pair<ll, ll>> v;
    for (int i=1; i<=m; i++) v.push_back({abs(w[i]-cw), i});
    sort(v.begin(), v.end());
    for (auto [_, i]:v)
    {
        if (find(a[i])==find(b[i])) 
        {
            if (i==idx) return 0;
            continue;
        }
        dsu[find(a[i])]=find(b[i]);
        if (i==idx) return 1;
    }
}

int32_t main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1; i<=m; i++) cin>>a[i]>>b[i]>>w[i];
    for (int i=1; i<=m; i++)
    {
        if (!isused(i, w[i])) continue;
        ll l=1, r=w[i];
        while (l<r)
        {
            ll md=(l+r)/2;
            if (isused(i, md)) r=md;
            else l=md+1;
        }
        add.push({l, i});
        l=w[i], r=2e9;
        while (l<r)
        {
            ll md=(l+r+1)/2;
            if (isused(i, md)) l=md;
            else r=md-1;
        }
        rem.push({l, i});
    }
    cin>>q;
    set<ll> edg;
    while (q--)
    {
        cin>>x;
        while (!add.empty()&&add.top().first<=x) edg.insert(add.top().second), add.pop();
        while (!rem.empty()&&rem.top().first<x) edg.erase(rem.top().second), rem.pop();
        ll res=0;
        for (auto tmp:edg) res+=abs(w[tmp]-x); //cout<<tmp<<' '<<a[tmp]<<' '<<b[tmp]<<' '<<w[tmp]<<'\n';
        cout<<res<<'\n'; 
        
    }
}

Compilation message

reconstruction.cpp:7: warning: ignoring '#pragma gcc ' [-Wunknown-pragmas]
    7 | #pragma gcc-optimize("o3, unroll-loops")
      | 
reconstruction.cpp: In function 'bool isused(long long int, long long int)':
reconstruction.cpp:24:26: warning: control reaches end of non-void function [-Wreturn-type]
   24 |     vector<pair<ll, ll>> v;
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 7 ms 504 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 182 ms 508 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3847 ms 12792 KB Output is correct
21 Correct 3813 ms 22396 KB Output is correct
22 Correct 3774 ms 22352 KB Output is correct
23 Correct 3854 ms 22352 KB Output is correct
24 Correct 3853 ms 22404 KB Output is correct
25 Correct 3781 ms 22432 KB Output is correct
26 Correct 4094 ms 22360 KB Output is correct
27 Correct 4288 ms 22304 KB Output is correct
28 Correct 3926 ms 22280 KB Output is correct
29 Correct 3935 ms 22316 KB Output is correct
30 Correct 4243 ms 22384 KB Output is correct
31 Correct 3859 ms 22132 KB Output is correct
32 Correct 2678 ms 22844 KB Output is correct
33 Correct 4014 ms 22360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 7 ms 504 KB Output isn't correct
21 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 7 ms 504 KB Output isn't correct
21 Halted 0 ms 0 KB -