Submission #168737

# Submission time Handle Problem Language Result Execution time Memory
168737 2019-12-15T16:56:47 Z Atashka01 Red-blue table (IZhO19_stones) C++11
100 / 100
67 ms 5240 KB
//Euzubillahimines-seytanir-rajim Bismillahir-rahmanir-rahym

/*
ID:
TASK:
LANG: C++
*/

#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define PII pair<int,int>
#define inf 1000000001
using namespace std;

int a[1001][1001], ans;

void f(int n,int m){
	
	vector<pair<int,int>> v;
	
	int k = n*m - ( m*(n/2+1) );
	
	k /= (m/2+1);
	
	ans = m + k;
	
	for(int i=1;i<=k;i++) v.push_back( {0,i} );
	
	for(int i=1;i<=m;i++){
		
		int l = k/2 + 1;
		int t = m/2 + 1;
		
		sort(v.begin(),v.end());
		
		for(int j=0;j<v.size();j++){
			
			if( l == 0) break;
			
			if( v[j].ff < t ){
				
				a[v[j].ss][i] = 1;
				v[j].ff++;
				l--;
				
			}
			
		}
		

		
	}
	
}

int t;

int main(){
	
	cin>>t;
	
	while(t--){
	
		int n, m;
		
		cin>>n>>m;
		
		if( n!= m ){
			
			f( min(n,m) , max(n,m) );
			
			cout<<ans<<"\n";
			
			if( n > m ){
				
				for(int i=n;i>=1;i--){
					
					for(int j=1;j<=m;j++) if( a[j][i] == 1 ){ cout<<"-"; a[j][i] = 0;}
					else cout<<"+";
					
					cout<<"\n";
					
				}
				
			}
			else{
				
				for(int i=1;i<=n;i++){
					
					for(int j=1;j<=m;j++) if(a[i][j] == 1){ cout<<"+"; a[i][j] = 0; }
					else cout<<"-";
					
					cout<<"\n";
					
				}
				
			}
			
		}
		else{
			
			f(n,m);
			
			cout<<ans<<"\n";
			
			for(int i=1;i<=n;i++){
				
				for(int j=1;j<=m;j++) if(a[i][j] == 1) {cout<<"+"; a[i][j] = 0;}
				else cout<<"-";
				
				cout<<"\n";
				
			}
			
		}
		
		
	}
	
}

/*
_________oBBBBB8o   oBBBBBBB8
_____o8BBBBBBBBBBB  BBBBBBBBB8        o88o
___o8BBBBBB**8BBBB  BBBBBBBBBB     oBBBBBBBo
__oBBBBBBB*   ***   BBBBBBBBBB     BBBBBBBBBBo
_8BBBBBBBBBBooooo   *BBBBBBB8      *BB* 8BBBBBBo
_8BBBBBBBBBBBBBBBB8ooBBBBBBB8           8BBBBBBB8
__*BBBBBBBBBBBBBBBBBBBBBBBBBB8 o88BB88BBBBBBBBBBBB
____*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8
______**8BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB*
___________*BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB8*
____________*BBBBBBBBBBBBBBBBBBBBBBBB8888**
_____________BBBBBBBBBBBBBBBBBBBBBBB*
_____________*BBBBBBBBBBBBBBBBBBBBB*
______________*BBBBBBBBBBBBBBBBBB8
_______________*BBBBBBBBBBBBBBBB*
________________8BBBBBBBBBBBBBBB8
_________________8BBBBBBBBBBBBBBBo
__________________BBBBBBBBBBBBBBB8
__________________BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBB8
__________________*BBBBBBBBBBBBBBBB
__________________8BBBBBBBBBBBBBBBB8
_________________oBBBBBBBBBBBBBBBBBB
________________oBBBBBBBBBBBBBBBBBBB
________________BBBBBBBBBBBBBBBBBBBB
_______________8BBBBBBBBBBBBBBBBBBB8
______________oBBBBBBBBB88BBBBBBBBB8
______________8BBBBBBBBB*8BBBBBBBBB*
______________BBBBBBBBB* BBBBBBBBB8
______________BBBBBBBB8 oBBBBBBBBB*
______________8BBBBBBB  oBBBBBBBB*
______________BBBBBBB*  8BBBBBBB*
_____________8BBBBBB*   BBBBBBB*
____________8BBBBBB8   oBBBBBB8
___________8BBBBBB8    8BBBBBB*
__________oBBBBBB8    BBBBBBB8
__________BBBBBBB8   BBBBBBBB*
_________oBBBBBBB8   BBBBBBBB
_________8BBBBBB8    BBBBBBB*
_________BBBBBB*     8BBBBB*
________oBBBB8       BBBBB*
________oBBB8        BBBB*
________BBBB8       8BBBBo
_______8BBBB*      oBBBBBBo
______8BBBB*       *BBBBBBBB8o
______BBBBB*            *88BBBo
*/

Compilation message

stones.cpp: In function 'void f(int, int)':
stones.cpp:47:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<v.size();j++){
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 420 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 1656 KB Output is correct
2 Correct 60 ms 4216 KB Output is correct
3 Correct 59 ms 4168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1940 KB Output is correct
2 Correct 58 ms 3972 KB Output is correct
3 Correct 52 ms 3320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 420 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 64 ms 1656 KB Output is correct
6 Correct 60 ms 4216 KB Output is correct
7 Correct 59 ms 4168 KB Output is correct
8 Correct 63 ms 1940 KB Output is correct
9 Correct 58 ms 3972 KB Output is correct
10 Correct 52 ms 3320 KB Output is correct
11 Correct 17 ms 636 KB Output is correct
12 Correct 50 ms 3292 KB Output is correct
13 Correct 52 ms 3064 KB Output is correct
14 Correct 38 ms 2416 KB Output is correct
15 Correct 67 ms 5240 KB Output is correct
16 Correct 48 ms 4216 KB Output is correct
17 Correct 23 ms 2552 KB Output is correct