Submission #376441

#TimeUsernameProblemLanguageResultExecution timeMemory
376441CaroLindaCultivation (JOI17_cultivation)C++14
0 / 100
2064 ms512 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) (int)(x.size() ) #define all(x) x.begin(),x.end() #define lp(i,a,b) for(int i= a ; i < b ; i++ ) #define pb push_back const int MAXN = 310 ; using namespace std ; /* O que acontece quando tem numa linha mais de uma coluna inserida? Se eu fizer set vai dar zika */ int N , R , C , ans = INT_MAX ; int mnNorth , mnSouth ; pair<int,int> seeds[MAXN] ; set< pair<int,int> > s ; multiset<int> values ; void add(int col, int id) { s.insert(make_pair(col,id) ) ; auto it = s.find( make_pair(col,id) ) ; auto it_less = it ; it_less-- ; auto it_more = it ; it_more++ ; if( it != s.begin() ) { if( it_more != s.end() ) values.erase( values.find(it_more->first - it_less->first) ) ; values.insert( col - it_less->first ) ; } if( it_more != s.end() ) values.insert( it_more->first - col ) ; } void rem(int col, int id ) { auto it = s.find( make_pair(col, id) ) ; auto it_less = it ; it_less-- ; auto it_more = it ; it_more++ ; if( it != s.begin() ) { values.erase( values.find( col - it_less->first ) ); if( it_more != s.end() ) values.insert( it_more->first - it_less->first ) ; } if( it_more != s.end() ) values.erase( values.find(it_more->first - col) ) ; s.erase( it ) ; } struct Event { int row , col , id , isClosing ; Event(int row = 0 , int col = 0 , int id = 0 , int isClosing = 0 ) : row(row), col(col) , id(id) , isClosing(isClosing) {} bool operator < ( Event other ) const { return make_pair(row, isClosing) < make_pair(other.row, other.isClosing) ; } } ; void test(int north,int south) { vector< Event > sweep ; for(int i= 1 ; i <= N ; i++ ) { sweep.push_back( Event( max(1, seeds[i].first-north) , seeds[i].second , i , 0 ) ) ; sweep.push_back( Event( min(seeds[i].first + south,R) , seeds[i].second , i , 1 ) ) ; if( seeds[i].first + south+1 <= R ) sweep.push_back( Event( seeds[i].first +south+1 , seeds[i].second , i , -1 ) ) ; } sort(all(sweep) ) ; int mx = 0 ; for(int i = 0 , ptr = 0 ; i < sz(sweep) ; i = ptr ) { int R = sweep[i].row ; while( ptr < sz(sweep) && sweep[ptr].row == R && sweep[ptr].isClosing != 1 ) { if( sweep[ptr].isClosing == 0 ) add( sweep[ptr].col , sweep[ptr].id ) ; ptr++ ; } int west_min = s.begin()->first - 1 ; int east_min = C - prev(s.end() )->first ; int k = ( values.empty() ) ? 0 : *prev(values.end() ) ; mx = max( {mx, west_min+east_min, k-1} ) ; while( ptr < sz(sweep) && sweep[ptr].row == R ) { if( sweep[ptr].isClosing == 1 ) rem(sweep[ptr].col , sweep[ptr].id ) ; ptr++ ; } } ans = min( ans , north+south + mx ) ; } int main() { scanf("%d %d %d", &R, &C, &N ) ; for(int i = 1 ; i <= N ; i++ ) scanf("%d %d", &seeds[i].first, &seeds[i].second ) ; sort(seeds+1, seeds+1+N) ; int mx = 0 ; for(int i= 1 ; i < N ; i++ ) mx = max(mx, seeds[i+1].first-seeds[i].first-1 ) ; mnNorth = seeds[1].first-1 ; mnSouth = R-seeds[N].first ; for(int i = mnNorth ; i <= R ; i++ ) for(int j = mnSouth ; j <= R ; j++ ) if( i+j >= mx ) test(i,j) ; /* for(int i = 1 ; i <= N ; i++ ) { for(int j = 1 ; j <= N ; j++ ) { int delta_row = seeds[i].first - seeds[j].first ; if( delta_row >= max( mnNorth + mnSouth , mx) ) test(delta_row) ; } if( seeds[i].first-1 >= max(mnNorth+mnSouth, mx) ) test(seeds[i].first-1) ; if( R-seeds[i].first >= max(mnNorth+mnSouth, mx) ) test(R-seeds[i].first) ; } */ printf("%d\n", ans ) ; }

Compilation message (stderr)

cultivation.cpp: In function 'int main()':
cultivation.cpp:121:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  121 |  scanf("%d %d %d", &R, &C, &N ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:122:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  122 |  for(int i = 1 ; i <= N ; i++ ) scanf("%d %d", &seeds[i].first, &seeds[i].second ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...