Submission #813551

# Submission time Handle Problem Language Result Execution time Memory
813551 2023-08-07T20:08:03 Z Ozy Fountain Parks (IOI21_parks) C++17
0 / 100
2 ms 212 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++) 
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define pll pair<lli,lli>

#define MAX 200000
//para los pares en general
#define xx first
#define yy second

lli n,a,b;
lli s[2] = {-1,1};
map<pll,lli> mapa,a_vis,p_vis;
lli dir[8] = {0,-1,0,1,1,0,-1,0};
vector<pll> aristas;
vector<int> u,v,b_x,b_y;

int construct_roads(std::vector<int> x, std::vector<int> y) {
    
    n = x.size();
    rep(i,0,n-1) {
        
        mapa[{x[i],y[i]}] = i;
        rep(j,0,3) {
            a = x[i] + dir[j];
            b = y[i] + dir[j+4];
            if(mapa.find({a,b}) != mapa.end()) aristas.push_back({i,mapa[{a,b}]});
        }

    }

    for (auto act : aristas) {
        while (a_vis.find(act) == a_vis.end()) {
            a_vis[act] = 1;
            swap(act.first,act.second);
            a_vis[act] = 1;

            //opciones para colocar la banca
            pll w = {(x[act.first] + x[act.second])/2, (y[act.first] + y[act.second])/2};
            pll z = {(x[act.first] + x[act.second])/2, (y[act.first] + y[act.second])/2};
            if (x[act.first] == x[act.second]) {
                w.xx++;
                z.xx--;
            }
            else {
                w.yy++;
                z.yy--;
            }

            if (p_vis.find(w) == mapa.end()) { //pongo mi banca en w
                b_x.push_back(w.xx);
                b_y.push_back(w.yy);
                u.push_back(w.first);
                v.push_back(w.second);
            }
            else {
                b_x.push_back(w.xx);
                b_y.push_back(w.yy);
                u.push_back(w.first);
                v.push_back(w.second);

                w = z;   
            }

            //busco si es que el esta en una tripleta y continuo la busqueda
            rep(i,0,1) {
                rep(j,0,1) {
                    z.xx = w.xx + s[i];
                    z.yy = w.yy + s[j];

                    if (z.xx == x[act.first] && z.yy == y[act.first]) continue;
                    if (z.xx == x[act.second] && z.yy == y[act.second]) continue;
                    if (mapa.find(z) == mapa.end()) continue;

                    if (z.xx == x[act.first] || z.yy == y[act.first]) act.second = mapa[z];
                    else act.first = mapa[z];
                }
            }

        }
        
    }

    build(u,v,b_x,b_y);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Given structure is not connected: There is no path between vertices 0 and 1
3 Halted 0 ms 0 KB -