답안 #561809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561809 2022-05-13T15:11:42 Z fcmalkcin Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
1951 ms 34328 KB
#include <bits/stdc++.h>
using namespace std;

#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=503;
const ll maxn1=1e5+10;
const ll mod=1e9+7  ;
const ll base=1e9;


/// i believe myself
/// goal 2/7

ll par[maxn];
ll find_par(ll u)
{
    if (par[u]<0)
        return u;
    return par[u]=find_par(par[u]);
}
bool dsu(ll x,ll y)
{
    x=find_par(x);
    y=find_par(y);
    if (x==y)
        return false;
    if (par[x]>par[y])
        swap(x,y);
    par[x]+=par[y];
    par[y]=x;
    return true;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll n, m;
    cin>> n>> m;
    vector<pair<ll,pll>> vt;
    vector<ll> vt1;
    for (int i=1; i<=m; i++)
    {
        ll x, y, w;
        cin>> x>> y>> w;
        vt.pb(make_pair(w,make_pair(x,y)));
    }
    sort(vt.begin(),vt.end());
    vector<pair<ll,pll>> vt2;
    for (int i=1;i<=m;i++)
    {
        ll j=i+1;
        memset(par,-1,sizeof(par));
        while (j<=m)
        {
            dsu(vt[j-1].ss.ff,vt[j-1].ss.ss);
            if (find_par(vt[i-1].ss.ff)==find_par(vt[i-1].ss.ss))
            {
                break;
            }
            j++;
        }
        ll k=i-1;
        memset(par,-1,sizeof(par));
        while (k)
        {
            dsu(vt[k-1].ss.ff,vt[k-1].ss.ss);
            if (find_par(vt[i-1].ss.ff)==find_par(vt[i-1].ss.ss))
            {
                break;
            }
            k--;
        }
        vt2.pb(make_pair((k==0?-1:(vt[k-1].ff+vt[i-1].ff+1)/2),make_pair(-1,vt[i-1].ff)));
        vt2.pb(make_pair(vt[i-1].ff,make_pair(2,-2*vt[i-1].ff)));
        vt2.pb(make_pair((j==m+1?base+1:(vt[j-1].ff+vt[i-1].ff+1)/2),make_pair(-1,vt[i-1].ff)));
    }
    ll sl=0;
    ll cnt=0;
    ll q;
    cin>> q;
    sort(vt2.begin(),vt2.end());
    ll id=0;
    for (int i=1;i<=q;i++)
    {
        ll x;
        cin>> x;
        while (id<vt2.size()&&vt2[id].ff<=x)
        {
            auto p=vt2[id].ss;
            sl+=p.ff;
            cnt+=p.ss;
            id++;
        }
        cout <<sl*x+cnt<<endl;
    }
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:102:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         while (id<vt2.size()&&vt2[id].ff<=x)
      |                ~~^~~~~~~~~~~
reconstruction.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
reconstruction.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1762 ms 16340 KB Output is correct
21 Correct 1341 ms 15144 KB Output is correct
22 Correct 1431 ms 15116 KB Output is correct
23 Correct 1517 ms 15264 KB Output is correct
24 Correct 1703 ms 15024 KB Output is correct
25 Correct 1698 ms 15080 KB Output is correct
26 Correct 1703 ms 16824 KB Output is correct
27 Correct 1719 ms 16792 KB Output is correct
28 Correct 1698 ms 16948 KB Output is correct
29 Correct 1049 ms 16820 KB Output is correct
30 Correct 1701 ms 16928 KB Output is correct
31 Correct 1729 ms 16808 KB Output is correct
32 Correct 1736 ms 16936 KB Output is correct
33 Correct 1755 ms 16640 KB Output is correct
34 Correct 663 ms 16784 KB Output is correct
35 Correct 1713 ms 16928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1738 ms 22252 KB Output is correct
5 Correct 1711 ms 32220 KB Output is correct
6 Correct 1703 ms 32124 KB Output is correct
7 Correct 928 ms 34004 KB Output is correct
8 Correct 701 ms 34296 KB Output is correct
9 Correct 611 ms 34280 KB Output is correct
10 Correct 1732 ms 32356 KB Output is correct
11 Correct 709 ms 34328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 183 ms 14060 KB Output is correct
21 Correct 203 ms 20220 KB Output is correct
22 Correct 233 ms 22356 KB Output is correct
23 Correct 201 ms 22416 KB Output is correct
24 Correct 208 ms 22396 KB Output is correct
25 Correct 216 ms 22360 KB Output is correct
26 Correct 268 ms 22276 KB Output is correct
27 Correct 277 ms 22348 KB Output is correct
28 Correct 188 ms 22344 KB Output is correct
29 Correct 219 ms 22300 KB Output is correct
30 Correct 224 ms 22420 KB Output is correct
31 Correct 186 ms 22124 KB Output is correct
32 Correct 190 ms 22752 KB Output is correct
33 Correct 191 ms 22336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1762 ms 16340 KB Output is correct
21 Correct 1341 ms 15144 KB Output is correct
22 Correct 1431 ms 15116 KB Output is correct
23 Correct 1517 ms 15264 KB Output is correct
24 Correct 1703 ms 15024 KB Output is correct
25 Correct 1698 ms 15080 KB Output is correct
26 Correct 1703 ms 16824 KB Output is correct
27 Correct 1719 ms 16792 KB Output is correct
28 Correct 1698 ms 16948 KB Output is correct
29 Correct 1049 ms 16820 KB Output is correct
30 Correct 1701 ms 16928 KB Output is correct
31 Correct 1729 ms 16808 KB Output is correct
32 Correct 1736 ms 16936 KB Output is correct
33 Correct 1755 ms 16640 KB Output is correct
34 Correct 663 ms 16784 KB Output is correct
35 Correct 1713 ms 16928 KB Output is correct
36 Correct 1723 ms 17008 KB Output is correct
37 Correct 1327 ms 17048 KB Output is correct
38 Correct 1418 ms 16952 KB Output is correct
39 Correct 1535 ms 16888 KB Output is correct
40 Correct 1748 ms 16496 KB Output is correct
41 Correct 1687 ms 16944 KB Output is correct
42 Correct 1723 ms 16724 KB Output is correct
43 Correct 1748 ms 16888 KB Output is correct
44 Correct 1707 ms 17096 KB Output is correct
45 Correct 1065 ms 16792 KB Output is correct
46 Correct 1728 ms 17064 KB Output is correct
47 Correct 1721 ms 16964 KB Output is correct
48 Correct 1730 ms 17004 KB Output is correct
49 Correct 1748 ms 17004 KB Output is correct
50 Correct 661 ms 16808 KB Output is correct
51 Correct 1733 ms 17088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1762 ms 16340 KB Output is correct
21 Correct 1341 ms 15144 KB Output is correct
22 Correct 1431 ms 15116 KB Output is correct
23 Correct 1517 ms 15264 KB Output is correct
24 Correct 1703 ms 15024 KB Output is correct
25 Correct 1698 ms 15080 KB Output is correct
26 Correct 1703 ms 16824 KB Output is correct
27 Correct 1719 ms 16792 KB Output is correct
28 Correct 1698 ms 16948 KB Output is correct
29 Correct 1049 ms 16820 KB Output is correct
30 Correct 1701 ms 16928 KB Output is correct
31 Correct 1729 ms 16808 KB Output is correct
32 Correct 1736 ms 16936 KB Output is correct
33 Correct 1755 ms 16640 KB Output is correct
34 Correct 663 ms 16784 KB Output is correct
35 Correct 1713 ms 16928 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1738 ms 22252 KB Output is correct
40 Correct 1711 ms 32220 KB Output is correct
41 Correct 1703 ms 32124 KB Output is correct
42 Correct 928 ms 34004 KB Output is correct
43 Correct 701 ms 34296 KB Output is correct
44 Correct 611 ms 34280 KB Output is correct
45 Correct 1732 ms 32356 KB Output is correct
46 Correct 709 ms 34328 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 183 ms 14060 KB Output is correct
49 Correct 203 ms 20220 KB Output is correct
50 Correct 233 ms 22356 KB Output is correct
51 Correct 201 ms 22416 KB Output is correct
52 Correct 208 ms 22396 KB Output is correct
53 Correct 216 ms 22360 KB Output is correct
54 Correct 268 ms 22276 KB Output is correct
55 Correct 277 ms 22348 KB Output is correct
56 Correct 188 ms 22344 KB Output is correct
57 Correct 219 ms 22300 KB Output is correct
58 Correct 224 ms 22420 KB Output is correct
59 Correct 186 ms 22124 KB Output is correct
60 Correct 190 ms 22752 KB Output is correct
61 Correct 191 ms 22336 KB Output is correct
62 Correct 1723 ms 17008 KB Output is correct
63 Correct 1327 ms 17048 KB Output is correct
64 Correct 1418 ms 16952 KB Output is correct
65 Correct 1535 ms 16888 KB Output is correct
66 Correct 1748 ms 16496 KB Output is correct
67 Correct 1687 ms 16944 KB Output is correct
68 Correct 1723 ms 16724 KB Output is correct
69 Correct 1748 ms 16888 KB Output is correct
70 Correct 1707 ms 17096 KB Output is correct
71 Correct 1065 ms 16792 KB Output is correct
72 Correct 1728 ms 17064 KB Output is correct
73 Correct 1721 ms 16964 KB Output is correct
74 Correct 1730 ms 17004 KB Output is correct
75 Correct 1748 ms 17004 KB Output is correct
76 Correct 661 ms 16808 KB Output is correct
77 Correct 1733 ms 17088 KB Output is correct
78 Correct 1948 ms 30984 KB Output is correct
79 Correct 1518 ms 30812 KB Output is correct
80 Correct 1604 ms 32244 KB Output is correct
81 Correct 1733 ms 32084 KB Output is correct
82 Correct 1848 ms 31320 KB Output is correct
83 Correct 1830 ms 30880 KB Output is correct
84 Correct 1871 ms 28176 KB Output is correct
85 Correct 1890 ms 31108 KB Output is correct
86 Correct 1942 ms 19936 KB Output is correct
87 Correct 1239 ms 25768 KB Output is correct
88 Correct 1899 ms 31268 KB Output is correct
89 Correct 1951 ms 31132 KB Output is correct
90 Correct 1948 ms 29572 KB Output is correct
91 Correct 1945 ms 19912 KB Output is correct
92 Correct 831 ms 22756 KB Output is correct
93 Correct 1950 ms 21020 KB Output is correct