Submission #1032175

#TimeUsernameProblemLanguageResultExecution timeMemory
1032175GrindMachineFlood (IOI07_flood)C++17
43 / 100
198 ms65536 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif /* refs: some hidden tcs (to identify the bug) read the edi a long time ago, remember some key ideas from there */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; vector<int> dx = {-1,1,0,0}; vector<int> dy = {0,0,-1,1}; void solve(int test_case) { ll n; cin >> n; vector<pll> a(n+5); rep1(i,n) cin >> a[i].ff >> a[i].ss; rep1(i,n) a[i].ff += 3, a[i].ss += 3; ll m; cin >> m; vector<pll> b(m+5); rep1(i,m) cin >> b[i].ff >> b[i].ss; set<array<ll,4>> st; rep1(i,m){ auto [x1,y1] = a[b[i].ff]; auto [x2,y2] = a[b[i].ss]; // same col if(x1 == x2){ if(y1 > y2) swap(y1,y2); for(int y = y1; y < y2; ++y){ st.insert({x1-1,y,x1,y}); st.insert({x1,y,x1-1,y}); } } // same row else if(y1 == y2){ if(x1 > x2) swap(x1,x2); for(int x = x1; x < x2; ++x){ st.insert({x,y1-1,x,y1}); st.insert({x,y1,x,y1-1}); } } else{ assert(0); } } ll siz = 0; rep1(i,n) amax(siz,a[i].ff), amax(siz,a[i].ss); ll dis[siz+5][siz+5]; bool vis[siz+5][siz+5]; memset(dis,0x3f,sizeof dis); memset(vis,0,sizeof vis); deque<pii> dq; dq.pb({0,0}); dis[0][0] = 0; while(!dq.empty()){ auto [i,j] = dq.front(); dq.pop_front(); if(vis[i][j]) conts; vis[i][j] = 1; rep(d,4){ int i2 = i+dx[d], j2 = j+dy[d]; if(i2 < 0 or i2 >= siz+5 or j2 < 0 or j2 >= siz+5) conts; if(st.count({i,j,i2,j2})){ if(dis[i][j]+1 < dis[i2][j2]){ dq.pb({i2,j2}); dis[i2][j2] = dis[i][j]+1; } } else{ if(dis[i][j] < dis[i2][j2]){ dq.push_front({i2,j2}); dis[i2][j2] = dis[i][j]; } } } } vector<ll> ans; rep1(i,m){ auto [x1,y1] = a[b[i].ff]; auto [x2,y2] = a[b[i].ss]; // same col if(x1 == x2){ if(y1 > y2) swap(y1,y2); bool ok = true; for(int y = y1; y < y2; ++y){ if(dis[x1-1][y] != dis[x1][y]){ ok = false; } } if(ok){ ans.pb(i); } for(int y = y1; y < y2; ++y){ assert(dis[x1-1][y] == dis[x1-1][y1]); } } // same row else if(y1 == y2){ if(x1 > x2) swap(x1,x2); bool ok = true; for(int x = x1; x < x2; ++x){ if(dis[x][y1-1] != dis[x][y1]){ ok = false; } } if(ok){ ans.pb(i); } for(int x = x1; x < x2; ++x){ assert(dis[x][y1-1] == dis[x1][y1-1]); } } else{ assert(0); } } cout << sz(ans) << endl; trav(x,ans) cout << x << endl; } int main() { fastio; int t = 1; // cin >> t; rep1(i, t) { solve(i); } return 0; }
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...