Submission #395739

# Submission time Handle Problem Language Result Execution time Memory
395739 2021-04-28T20:10:26 Z CaroLinda Red-blue table (IZhO19_stones) C++14
42 / 100
73 ms 1420 KB
#include <bits/stdc++.h>

#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)(x.size())

const int LOG = 20 ;
const int MAXN=2e5+10 ;

using namespace std ;

int T , N , M , K ;

void solve()
{
	scanf("%d %d", &N, &M ) ;
	K = (N+2)>>1 ;

	vector<int> freq(N,M) ;
	vector< vector<char> > grid( N , vector<char>(M,'+') ) ;

	int bestAns = N ;
	int ans = N+1 , L = 0 , id = 0 ;
	bool ok = true ;

	for(int i = 0 ; i < M ; i++ , ans++ )
	{
		int cnt = K ;
		while( cnt-- && ok )
		{
			if( id == N ) id = L ;
			
			grid[id][i] = '-' ;
			freq[id]-- ;
			
			if( freq[id]*2 <= M )
			{
				for(int j = i+1 ; j < M ; j++ ) grid[id][j] = '-' ;
				K-- ;
				L++ ;
				ans-- ;
			}
			id++ ;
		}

		bestAns = max(ans, bestAns ) ;
 	}

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

 	for(int i = 0 ; i < N  ; i++ )
 	{
 		for(int j = 0 ; j < M ; j++ ) grid[i][j] = '+' ; 
 		freq[i] = M ;
 	}


 	if(bestAns > N)
 	{
	 	K = (N+2)>>1 ;
	 	L = id = 0 ;
	 	ans = N+1 ;

	 	for(int i = 0 ; i < M  ; i++ , ans++ )
		{
			int cnt = K ;
			while( cnt-- )
			{
				if( id == N ) id = L ;
				
				grid[id][i] = '-' ;
				freq[id]-- ;
				
				if( freq[id]*2 <= M )
				{
					for(int j = i+1 ; j < M ; j++ ) grid[id][j] = '-' ;
					K-- ;
					L++ ;
					ans-- ;
				}
				id++ ;
			}

			if( ans == bestAns ) break ;
	 	}
	 }

 	for(int i = 0 ; i < N ; i++ , printf("\n") )
 		for(int j = 0 ; j < M ; j++ ) printf("%c", grid[i][j] ) ;
}

int main()
{
	scanf("%d", &T ) ;
	while(T--) solve() ;
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  scanf("%d %d", &N, &M ) ;
      |  ~~~~~^~~~~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   97 |  scanf("%d", &T ) ;
      |  ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Incorrect 4 ms 332 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 1256 KB Wrong answer in test 23 57: 76 < 78
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 1220 KB Output is correct
2 Correct 69 ms 1420 KB Output is correct
3 Correct 54 ms 1304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Incorrect 4 ms 332 KB Wrong answer in test 5 29: 31 < 32