Submission #598879

#TimeUsernameProblemLanguageResultExecution timeMemory
598879balbitFountain Parks (IOI21_parks)C++17
70 / 100
608 ms68080 KiB
// 我的心裡只有你沒有他 #include "parks.h" #include <bits/stdc++.h> // #define int ll using namespace std; #define ll long long #define y1 zck_is_king #define pii pair<ll, ll> #define ull unsigned ll #define f first #define s second #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define SQ(x) (x)*(x) #define MN(a,b) a = min(a,(__typeof__(a))(b)) #define MX(a,b) a = max(a,(__typeof__(a))(b)) #define pb push_back #define REP(i,n) for (int i = 0; i<n; ++i) #define RREP(i,n) for (int i = n-1; i>=0; --i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #ifdef BALBIT #define IOS() #define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__); template<typename T> void _do(T &&x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);} #else #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define bug(...) #endif const int maxn = 4e5+5; vector<int> rU,rV,rA,rB; set<pii> used; // benches in use map<pii, int> id; void ADD(int u, int v, int a, int b) { rU.pb(u); rV.pb(v); rA.pb(a); rB.pb(b); used.insert({a,b}); } int GET(int x, int y){ return id.count({x,y})?id[{x,y}]:-1; } int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; bool seen[maxn]; vector<int> X, Y; void dfs(int v, int sd) { //sd: starting direction seen[v]= 1; int x = X[v], y = Y[v]; for (int df = 0; df < 4; ++df) { int d = (df + sd) % 4; int tx = x + dx[d]*2, ty = y + dy[d]*2; int u = GET(tx,ty); if (u == -1 || seen[u]) continue; int pd = (d-1+4)%4; int nxtd = (d+1)%4; int b1x = x + dx[d] + dx[pd], b1y = y + dy[d] + dy[pd]; int b2x = x + dx[d] + dx[nxtd], b2y = y + dy[d] + dy[nxtd]; bug(v,u,d); bug(b1x,b1y); bug(b2x,b2y); if (!used.count({b1x, b1y})) { ADD(u,v,b1x,b1y); }else{ if (used.count({b2x, b2y})) { continue; } assert(!used.count({b2x,b2y})); ADD(u,v,b2x,b2y); } dfs(u, pd); } } int construct_roads(std::vector<int> _x, std::vector<int> _y) { X = _x, Y = _y; int n = SZ(X); REP(i,n) { id[{X[i], Y[i]}] = i; } dfs(0, 0); if (SZ(rU) < n-1) return 0; build(rU,rV,rA,rB); return 1; } /* 4, 4, 6, 4, 2], [4, 6, 4, 2, 4 5 4 4 4 6 6 4 4 2 2 4 25 -4 4 0 0 0 2 0 4 0 6 0 8 -2 0 -2 2 -2 4 -2 6 -2 8 -4 0 -4 2 -4 6 -4 8 -6 0 -6 2 -6 4 -6 6 -6 8 -8 0 -8 2 -8 4 -8 6 -8 8 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...