Submission #603196

#TimeUsernameProblemLanguageResultExecution timeMemory
603196definitelynotmeeRectangles (IOI19_rect)C++17
13 / 100
590 ms196264 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using matrix = vector<vector<T>>; #define ff first #define ss second #define all(x) x.begin(), x.end() struct cebola{ int pai, minx, maxx, miny, maxy, sz; }; long long count_rectangles(std::vector<std::vector<int> > a) { int n = a.size(), m = a[0].size(); int tot = n*m; int resp = 0; if(n > 3){ vector<cebola> v(tot); for(int i = 0; i < tot; i++){ v[i] = {i,i%m,i%m,i/m,i/m,1}; } auto find =[&](int id, auto find){ if(v[id].pai == id) return id; return v[id].pai = find(v[id].pai,find); }; auto onion =[&](int a, int b){ a= find(a,find); b = find(b,find); if(a == b) return; v[a].pai = b; v[b].minx = min(v[b].minx,v[a].minx); v[b].miny = min(v[b].miny,v[a].miny); v[b].maxx = max(v[b].maxx,v[a].maxx); v[b].maxy = max(v[b].maxy,v[a].maxy); v[b].sz+=v[a].sz; }; int dx[]{1,0,-1,0}, dy[]{0,1,0,-1}; for(int i = 0; i < tot; i++){ int x = i%m, y = i/m; for(int j = 0; j < 4; j++){ int xi = x + dx[j], yi = y+ dy[j]; if(xi < 0 || xi >= m || yi < 0 || yi >= n){ continue; } int id = yi*m+xi; // cout << dx[j] << ' ' << dy[j] << '\n'; // cout << "->" << i << ' '<< x << ' ' << y << " <=> " << id << ' ' <<xi << ' ' << yi << '\n'; if(a[y][x] == 0 && a[yi][xi] == 0) onion(i,id) ; } } for(int i = 0; i < tot; i++){ int x = i%m, y = i/m; if(a[y][x] != 0 || v[i].pai != i) continue; // cout << x << ' ' << y << '\n'; // cout << v[i].minx << ' ' << v[i].maxx << ' ' << v[i].miny << ' ' << v[i].maxy << '\n'; if(v[i].maxx == m-1 || v[i].minx == 0 || v[i].miny == 0 || v[i].maxy == n-1) continue; //cout << x << ' ' << y << '\n'; if((v[i].maxx-v[i].minx+1)*(v[i].maxy-v[i].miny+1) == v[i].sz) resp++; } } else { if(n <= 2 || m <= 2) return 0; for(int i = 1; i < n-1; i++){ int maxrange = -1, okcol = 1; for(int j = i; j < n-1 && okcol; j++){ maxrange = max(maxrange,a[1][j]); okcol&=a[1][j] < a[0][j] && a[1][j] < a[2][j]; if(okcol && maxrange < a[1][i-1] && maxrange < a[1][j+1]) resp++; } } } return resp; }
#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...