제출 #1109742

#제출 시각아이디문제언어결과실행 시간메모리
1109742kuka_123Red-blue table (IZhO19_stones)C++14
100 / 100
25 ms2384 KiB
                              /*Bismillahir Rahmanir Raheem*/
#include <bits/stdc++.h>
  
using namespace std;

#define kuka ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define FOR(n) for(int i = 0; i < n; i++)
#define ff(x, y) for( int y = 0; y < x; y++)
#define fff(x, y) for( int y = x; y <= 0; y--)
#define F first
#define S second
#define int long long  

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = LLONG_MAX;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;	 

char a[1002][1002];
int col[1001], mp[1001];

void oyan(){
	int n, m, mx, ans = 0;
	cin>>n>>m;
	if(n <= m){
		for(int i = 1; i <= n; i ++){
			for(int j = 1; j <= m; j ++){
				a[i][j] = '-';
				col[j] = (n - 1) / 2;
			}
		}
		mp[(n - 1) / 2] = m;
		mx = (n - 1) / 2 ;
		for(int i = 1; i <= n; i++){
			int sum = 0, colmx = m / 2 + 1;
			if(mp[mx] <= (m / 2) + 1){
				colmx-=mp[mx];
				mp[mx] = 0;
				mx--;
			}
			//cout<<mx<<"\n";
			for(int j = 1; j <= m; j++){
				if(sum > m / 2){
					ans++;sum = 0;
					break;
				}
				if(col[j] > mx and col[j] != 0){
					col[j] --;
					mp[col[j]]++;
					a[i][j] = '+';
					sum++;
				}
				if(col[j] == mx and col[j] != 0){
					if(!colmx)continue;
					mp[col[j]]--;
					col[j]--;
					mp[col[j]]++;
					a[i][j] = '+';
					sum++;
					colmx--;
				}
				//cout<<col[j]<< " "<<sum<<" "<<colmx<<"\n";
			}
			if(sum > m / 2){
				ans++;sum = 0;
			}
		}
		ans+=m;
	}else{
		for(int i = 1; i <= n; i ++){
			for(int j = 1; j <= m; j ++){
				a[i][j] = '+';
			}
			col[i] = (m - 1) / 2;
		}
		mp[(m - 1) / 2] = n;
		mx = (m - 1) / 2;
		for(int j = 1; j <= m; j++){
			int sum = 0, colmx = n / 2 + 1;
			if(mp[mx] <= (n / 2) + 1){
				colmx-=mp[mx];
				mp[mx] = 0;
				mx--;
			}
			//cout<<mx<<"\n";
			for(int i = 1; i <= n; i++){
				if(sum > n / 2){
					ans++;sum = 0;
					break;
				}
				if(col[i] > mx and col[i] != 0){
					col[i] --;
					mp[col[i]]++;
					a[i][j] = '-';
					sum++;
				}
				if(col[i] == mx and col[i] != 0){
					if(!colmx)continue;
					mp[col[i]]--;
					col[i]--;
					mp[col[i]]++;
					a[i][j] = '-';
					sum++;
					colmx--;
				}
				//cout<<col[j]<< " "<<sum<<" "<<colmx<<"\n";
			}
			if(sum > n / 2){
				ans++;sum = 0;
			}
		}
		ans+=n;
	}
	cout<<ans<<"\n";
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j++){
			cout<<a[i][j];
		}
		cout<<"\n";
	}
}		 	

main(){
    //kuka;
	//freopen("test.txt", "r", stdin);
	//freopen("distance.in", "r", stdin);
    //freopen("distance.out", "w", stdout);
    int oylan = 1;
    cin>>oylan;
    while(oylan--){
        oyan();
    }
}
/*
NOTES
a/b module == (a*b^(module - 2)) % (module);
*/

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp:131:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  131 | main(){
      | ^~~~
#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...