Submission #481731

# Submission time Handle Problem Language Result Execution time Memory
481731 2021-10-21T13:32:34 Z Fysty Fountain Parks (IOI21_parks) C++17
45 / 100
620 ms 62568 KB
#include <bits/stdc++.h>
#include "parks.h"
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll ans=fpow(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
const int N=2e5+1;
bool vis[N<<2];
vector<int> x,y;
vector<int> retu,retv,a,b;
vector<pii> ed[N<<2];
pii point[N],pos[N<<2];
set<pii> edges;
map<pii,int> id,id2;
int n,tn=0,cnt=0;
int par[N];
int fp(int u){return u==par[u]?u:par[u]=fp(par[u]);}
int unite(int u,int v)
{
    if(fp(u)==fp(v)) return 0;
    par[fp(v)]=fp(u);
    return 1;
}

/*void build(vector<int> v1,vector<int> v2,vector<int> v3,vector<int> v4)
{
    for(ll u:v1) cout<<u<<" ";
    cout<<"\n";
    for(ll u:v2) cout<<u<<" ";
    cout<<"\n";
    for(ll u:v3) cout<<u<<" ";
    cout<<"\n";
    for(ll u:v4) cout<<u<<" ";
    cout<<"\n";
}
*/
void solve()
{
    for(pii tmp:edges)
    {
        int u=tmp.F,v=tmp.S;
        int can=unite(u,v);
        if(can)
        {
            cnt++;
            retu.pb(u);
            retv.pb(v);
            if(y[u]==y[v])
            {
                int mid=(x[u]+x[v])>>1;
                if((mid+y[u]+1)%4==0)
                {
                    a.pb(mid);
                    b.pb(y[u]+1);
                }
                else
                {
                    a.pb(mid);
                    b.pb(y[u]-1);
                }
            }
            else
            {
                int mid=(y[u]+y[v])>>1;
                if((mid+x[u]+1)%4==2)
                {
                    a.pb(x[u]+1);
                    b.pb(mid);
                }
                else
                {
                    a.pb(x[u]-1);
                    b.pb(mid);
                }
            }
            //if(b.back()<2) {dbg(u,v,b.back());}
        }
    }
}
void dfs(int u)
{
    vis[u]=1;
    for(pii tmp:ed[u])
    {
        if(vis[tmp.F]) continue;
        pii p=pos[tmp.F];
        if(tmp.S==1)
        {
            edges.erase({id[{p.F+1,p.S-1}],id[{p.F+1,p.S+1}]});
        }
        else if(tmp.S==2)
        {
            edges.erase({id[{p.F-1,p.S-1}],id[{p.F-1,p.S+1}]});
        }
        else if(tmp.S==3)
        {
            edges.erase({id[{p.F-1,p.S-1}],id[{p.F+1,p.S-1}]});
        }
        else if(tmp.S==4)
        {
            edges.erase({id[{p.F-1,p.S+1}],id[{p.F+1,p.S+1}]});
        }
        dfs(tmp.F);
    }
}
int construct_roads(vector<int> X,vector<int> Y) {
    x=X;
    y=Y;
    n=x.size();
    if(n==1)
	{
	    build(retu,retv,a,b);
        return 1;
    }
    rep(i,n)
    {
        point[i]={x[i],y[i]};
        id[point[i]]=i;
    }
    rep(i,n)
    {
        int tmp=0;
        if(id.count({x[i]+2,y[i]}))
        {
            edges.insert({id[{x[i]+2,y[i]}],i});
            tmp++;
        }
        if(id.count({x[i],y[i]+2}))
        {
            edges.insert({id[{x[i],y[i]+2}],i});
            tmp++;
        }
        if(tmp==2)
        {
            if(id.count({x[i]+2,y[i]+2}))
            {
                tn++;
                pos[tn]={x[i]+1,y[i]+1};
                id2[{x[i]+1,y[i]+1}]=tn;
            }
        }
    }
    rep1(i,tn)
    {
        pii tmp=pos[i];
        if((tmp.F+tmp.S)%4==0)
        {
            if(id2.count({tmp.F,tmp.S-2}))
            {
                int u=id2[{tmp.F,tmp.S-2}];
                ed[i].pb({u,4});
                ed[u].pb({i,3});
            }
            else ed[0].pb({i,3});
            if(id2.count({tmp.F,tmp.S+2}))
            {
                int u=id2[{tmp.F,tmp.S+2}];
                ed[i].pb({u,3});
                ed[u].pb({i,4});
            }
            else ed[0].pb({i,4});
        }
        else
        {
            if(id2.count({tmp.F-2,tmp.S}))
            {
                int u=id2[{tmp.F-2,tmp.S}];
                ed[i].pb({u,1});
                ed[u].pb({i,2});
            }
            else ed[0].pb({i,2});
            if(id2.count({tmp.F+2,tmp.S}))
            {
                int u=id2[{tmp.F+2,tmp.S}];
                ed[i].pb({u,2});
                ed[u].pb({i,1});
            }
            else ed[0].pb({i,1});
        }
    }
    if(tn>0)
    {
        dfs(0);
    }
    rep(i,n) par[i]=i;
    solve();
    if(cnt<n-1) return 0;
    else
    {
        build(retu,retv,a,b);
        return 1;
    }
}
/*
for blocks:
    if (x+y)%4==0 then ud
    if (x+y)%4==2 then lr
direction:
    1: left
    2: right
    3: up
    4: down
*/
/*
signed main()
{
    MottoHayaku
    vector<int> X,Y;
    int tx,ty;
    while(cin>>tx>>ty)
    {
        X.pb(tx);
        Y.pb(ty);
    }

    ll res=construct_roads(X,Y);
    cout<<res<<"\n";
}
*/

# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
17 Incorrect 9 ms 19104 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
17 Incorrect 9 ms 19104 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
17 Correct 9 ms 19036 KB Output is correct
18 Correct 9 ms 19052 KB Output is correct
19 Correct 10 ms 19012 KB Output is correct
20 Correct 528 ms 60016 KB Output is correct
21 Correct 509 ms 59704 KB Output is correct
22 Correct 519 ms 59708 KB Output is correct
23 Correct 393 ms 53528 KB Output is correct
24 Correct 262 ms 40464 KB Output is correct
25 Correct 484 ms 52892 KB Output is correct
26 Correct 451 ms 53024 KB Output is correct
27 Correct 497 ms 59112 KB Output is correct
28 Correct 491 ms 59116 KB Output is correct
29 Correct 549 ms 59180 KB Output is correct
30 Correct 568 ms 59160 KB Output is correct
31 Correct 9 ms 19020 KB Output is correct
32 Correct 30 ms 22304 KB Output is correct
33 Correct 93 ms 30116 KB Output is correct
34 Correct 481 ms 60684 KB Output is correct
35 Correct 23 ms 20940 KB Output is correct
36 Correct 84 ms 27800 KB Output is correct
37 Correct 191 ms 36496 KB Output is correct
38 Correct 161 ms 35788 KB Output is correct
39 Correct 241 ms 41812 KB Output is correct
40 Correct 338 ms 48072 KB Output is correct
41 Correct 449 ms 54520 KB Output is correct
42 Correct 567 ms 60600 KB Output is correct
43 Correct 9 ms 19020 KB Output is correct
44 Correct 10 ms 19104 KB Output is correct
45 Correct 9 ms 19020 KB Output is correct
46 Correct 9 ms 19020 KB Output is correct
47 Correct 9 ms 19092 KB Output is correct
48 Correct 9 ms 19020 KB Output is correct
49 Correct 9 ms 19004 KB Output is correct
50 Correct 9 ms 19112 KB Output is correct
51 Correct 9 ms 19020 KB Output is correct
52 Correct 9 ms 19100 KB Output is correct
53 Correct 9 ms 19100 KB Output is correct
54 Correct 10 ms 19404 KB Output is correct
55 Correct 12 ms 19648 KB Output is correct
56 Correct 187 ms 39196 KB Output is correct
57 Correct 319 ms 48220 KB Output is correct
58 Correct 335 ms 48224 KB Output is correct
59 Correct 9 ms 19020 KB Output is correct
60 Correct 9 ms 19116 KB Output is correct
61 Correct 9 ms 19020 KB Output is correct
62 Correct 457 ms 59148 KB Output is correct
63 Correct 449 ms 59324 KB Output is correct
64 Correct 456 ms 59036 KB Output is correct
65 Correct 13 ms 19788 KB Output is correct
66 Correct 17 ms 20480 KB Output is correct
67 Correct 193 ms 39172 KB Output is correct
68 Correct 347 ms 49308 KB Output is correct
69 Correct 532 ms 59276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
17 Correct 485 ms 59516 KB Output is correct
18 Correct 473 ms 59544 KB Output is correct
19 Correct 523 ms 59712 KB Output is correct
20 Correct 614 ms 61468 KB Output is correct
21 Correct 479 ms 55204 KB Output is correct
22 Correct 9 ms 19100 KB Output is correct
23 Correct 63 ms 26336 KB Output is correct
24 Correct 46 ms 23116 KB Output is correct
25 Correct 128 ms 32164 KB Output is correct
26 Correct 261 ms 40976 KB Output is correct
27 Correct 232 ms 40688 KB Output is correct
28 Correct 314 ms 46372 KB Output is correct
29 Correct 419 ms 52012 KB Output is correct
30 Correct 531 ms 56740 KB Output is correct
31 Correct 620 ms 62568 KB Output is correct
32 Correct 571 ms 61208 KB Output is correct
33 Correct 442 ms 59268 KB Output is correct
34 Correct 14 ms 19960 KB Output is correct
35 Correct 19 ms 20812 KB Output is correct
36 Correct 221 ms 39680 KB Output is correct
37 Correct 379 ms 50008 KB Output is correct
38 Correct 547 ms 60240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19020 KB Output is correct
2 Correct 8 ms 19008 KB Output is correct
3 Correct 9 ms 19020 KB Output is correct
4 Correct 9 ms 19020 KB Output is correct
5 Correct 9 ms 19084 KB Output is correct
6 Correct 9 ms 19020 KB Output is correct
7 Correct 9 ms 19104 KB Output is correct
8 Correct 9 ms 19020 KB Output is correct
9 Correct 197 ms 39288 KB Output is correct
10 Correct 20 ms 21356 KB Output is correct
11 Correct 70 ms 29996 KB Output is correct
12 Correct 25 ms 22316 KB Output is correct
13 Correct 48 ms 26692 KB Output is correct
14 Correct 10 ms 19276 KB Output is correct
15 Correct 12 ms 19404 KB Output is correct
16 Correct 173 ms 39172 KB Output is correct
17 Incorrect 9 ms 19104 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -