Submission #960396

#TimeUsernameProblemLanguageResultExecution timeMemory
960396LucaIlieIOI Fever (JOI21_fever)C++17
11 / 100
1 ms2648 KiB
#include <bits/stdc++.h> using namespace std; struct house { int x, y; }; const int MAX_N = 2e5; const int INF = 5e8; int dir[MAX_N], t[MAX_N]; house houses[MAX_N]; unordered_map<int, set<pair<int, int>>> diag1, diag2, vert, horiz; set<pair<int, int>> q; void visitt( set<pair<int, int>> &s, int l, int r, int i, int d ) { vector<int> del; auto p = s.lower_bound( { l, 0 } ); while ( p != s.end() && p->first <= r ) { int j = p->second; del.push_back( j ); q.insert( { houses[j].x, j } ); if ( houses[i].x == houses[j].x ) t[j] = abs( houses[j].y - houses[i].y ) / 2; else if ( houses[i].y == houses[j].y ) t[j] = abs( houses[j].x - houses[j].x ) / 2; else t[j] = abs( houses[j].x - houses[i].x ); dir[j] = d; p++; } for ( int j: del ) { diag1[houses[j].x + houses[j].y].erase( { houses[j].x, j } ); diag2[houses[j].x - houses[j].y].erase( { houses[j].x, j } ); vert[houses[j].x].erase( { houses[j].y, j } ); horiz[houses[j].y].erase( { houses[j].x, j } ); } } int main() { int n; cin >> n; for ( int i = 0; i < n; i++ ) cin >> houses[i].x >> houses[i].y; int maxVisited = 0; for ( int d = 0; d < 4; d++ ) { diag1.clear(); diag2.clear(); for ( int i = 1; i < n; i++ ) { diag1[houses[i].x + houses[i].y].insert( { houses[i].x, i } ); diag2[houses[i].x - houses[i].y].insert( { houses[i].x, i } ); vert[houses[i].x].insert( { houses[i].y, i } ); horiz[houses[i].y].insert( { houses[i].x, i } ); } int visited = 0; q.insert( { houses[0].x, 0 } ); dir[0] = d; t[0] = 0; while ( !q.empty() ) { int i = q.begin()->second; q.erase( { houses[i].x, i } ); //printf( "%d (%d %d) %d %d\n", i, houses[i].x, houses[i].y, t[i], dir[i] ); visited++; int x = houses[i].x, y = houses[i].y; if ( dir[i] == 0 ) { visitt( vert[x], y + t[i], INF, i, 1 ); visitt( diag1[x + y], -INF, x - t[i], i, 2 ); visitt( diag2[x - y], x + t[i], INF, i, 3 ); } else if ( dir[i] == 1 ) { visitt( vert[x], -INF, y - t[i], i, 0 ); visitt( diag1[x + y], x + t[i], INF, i, 3 ); visitt( diag2[x - y], -INF, x - t[i], i, 2 ); } else if ( dir[i] == 2 ) { visitt( horiz[y], x + t[i], INF, i, 3 ); visitt( diag1[x + y], x + t[i], INF, i, 0 ); visitt( diag2[x - y], x + t[i], INF, i, 1 ); } else if ( dir[i] == 3 ) { visitt( horiz[y], -INF, x - t[i], i, 2 ); visitt( diag1[x + y], -INF, x - t[i], i, 1 ); visitt( diag2[x - y], -INF, x - t[i], i, 0 ); } } //printf( "DIR %d: %d\n", d, visited ); maxVisited = max( maxVisited, visited ); } cout << maxVisited; return 0; } /* * d == 0 sus * d == 1 jos * d == 2 dreapta * d == 3 stanga */
#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...