답안 #395737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395737 2021-04-28T20:08:37 Z CaroLinda Red-blue table (IZhO19_stones) C++14
0 / 100
75 ms 1616 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] = '+' ; 

 	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:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   93 |  scanf("%d", &T ) ;
      |  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 332 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB in the table A+B is not equal to 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 1616 KB in the table A+B is not equal to 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 1212 KB in the table A+B is not equal to 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB in the table A+B is not equal to 5