Submission #376450

# Submission time Handle Problem Language Result Execution time Memory
376450 2021-03-11T13:38:03 Z CaroLinda Cultivation (JOI17_cultivation) C++14
5 / 100
2000 ms 492 KB
#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 ;
	int west_min = 0 , east_min = 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++ ;
		}

		west_min = max(west_min , s.begin()->first - 1 ) ;
		east_min = max(east_min, C - prev(s.end() )->first ) ;
		int k = ( values.empty() ) ? 0 : *prev(values.end() ) ;

		mx = max(mx, k-1) ;

		while( ptr < sz(sweep) && sweep[ptr].row == R  )
		{
			if( sweep[ptr].isClosing == 1 )
				rem(sweep[ptr].col , sweep[ptr].id ) ;
			ptr++ ;
		}

	}

	mx = max(mx, west_min + east_min ) ;

	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 ;

	vector<int> conj ;

	for(int i = 1 ; i <= N ; i++ )
	{
		for(int j = i ; j <= N ; j++ ) conj.push_back( seeds[j].first - seeds[i].first - 1) ;
		conj.push_back( seeds[i].first-1 ) ;
		conj.push_back( R-seeds[i].first ) ;
	}

	for(auto north : conj )
		for(auto south : conj )
			if( north >= mnNorth && south >= mnSouth && north + south >= mx ) 
				test(north,south ) ;

	printf("%d\n", ans ) ;

}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:123:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  123 |  scanf("%d %d %d", &R, &C, &N ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:124:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  124 |  for(int i = 1 ; i <= N ; i++ ) scanf("%d %d", &seeds[i].first, &seeds[i].second ) ;
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 10 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 65 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 10 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 65 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 452 ms 376 KB Output is correct
18 Execution timed out 2029 ms 364 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 10 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 65 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 452 ms 376 KB Output is correct
18 Execution timed out 2029 ms 364 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 162 ms 492 KB Output is correct
2 Correct 1381 ms 492 KB Output is correct
3 Correct 1637 ms 388 KB Output is correct
4 Incorrect 1295 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 162 ms 492 KB Output is correct
2 Correct 1381 ms 492 KB Output is correct
3 Correct 1637 ms 388 KB Output is correct
4 Incorrect 1295 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 10 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 65 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 452 ms 376 KB Output is correct
18 Execution timed out 2029 ms 364 KB Time limit exceeded
19 Halted 0 ms 0 KB -