답안 #879048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879048 2023-11-26T07:53:03 Z Elvin_Fritl Red-blue table (IZhO19_stones) C++17
53 / 100
39 ms 4004 KB
#include <bits/stdc++.h>
using namespace std;
 
#define io                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

 
typedef long long ll;
 
ll bp(ll n,ll m){
    if(m == 0){
        return 1;
    }
    if(m == 1){
        return n;
    }
    if(m%2==0){
        return bp(n*n,m/2);
    }
    return n*bp(n,m-1);
}

 
const int N =  1020, M = 33, inf = 1e9 + 99;
const ll inff = 1e12;
 
 
 void solve() {
	 int n,m;
	 cin >> n >> m;
	 vector<vector<int>>a(n + 1 , vector<int>(m + 1 , 0));
			
	if(n <= 4 || m <= 4) {
		if(n<=m) {
			cout << (n-1)/2 + m << endl;
			int x = (n-1)/2;
			for(int i=1;i<=n - x;i++) {
				for(int j=1;j<=m;j++) {
					a[i][j] = -1;
				}
			}
			for(int i=1;i<=x; i++) {
				for(int j=1;j<=m;j++) {
					a[i][j] = 1;
				}
			}
			for(int i=1;i<=n;i++) {
				for(int j=1;j<=m;j++) {
					cout << (a[i][j] == 1 ? '+' : '-');
				}
				cout<<endl;
			}
		} 
		else {
			cout << (m-1)/2+n << endl;
			int x = (m-1)/2;
			for(int i=1;i<=n;i++) {
				for(int j=1;j<=x;j++) {
					a[i][j] = -1;
				}
				for(int j=1;j<=m- x;j++){
					a[i][j] = 1;
				}
			}
			for(int i=1;i<=n;i++) {
				for(int j=1;j<=m;j++) {
					cout << (a[i][j] == 1 ? '+' : '-');
				}
				cout<<endl;
			}
		}
	} 
	else if(n == m && n == 6) {
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=3;j++){
				a[i][j] = 1;
			}
		}
		int tmp=(n/2 - 2)*n, x=1, y=n;
		while(tmp > 0) {
			tmp--;
			a[x][y] = 1;
			x++;
			y--;
			if(y==3){
				y=n;
			}
			if(x==n+1){
				x=1;
			}
		}
		cout << n + m - 3 << endl;
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				cout << (a[i][j] == 1 ? '+' : '-');
			}
			cout<<endl;
		}
	} 
	else {
		for(int i=1; i<=n-(n-1)/2; i++) {
			for(int j=1; j<=(m-1)/2; j++) {
				a[i][j] = -1;
			}
		}
		for(int i=(n-1)/2+1;i<=n;i++) {
			for(int j=(m)/2+2;j<=m;j++) {
				a[i][j] = -1;
			}
		}
		cout << 2*((n-1)/2 + (m-1)/2) << endl;
		for(int i=1;i<=n;i++) {
			for(int j=1;j<=m;j++) {
				cout << (a[i][j] == -1 ? '-' : '+');
			}
			cout<<endl;
		}
	}
}
 
int main()
{
	io;
	
	int t;
	cin >> t;
	while(t--) {
		solve();
	}
    
    return 0;
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Incorrect 10 ms 348 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 1372 KB Output is correct
2 Correct 19 ms 3600 KB Output is correct
3 Correct 18 ms 4004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 1628 KB Output is correct
2 Correct 17 ms 2960 KB Output is correct
3 Correct 15 ms 2148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Incorrect 10 ms 348 KB Wrong answer in test 38 5: 40 < 41
5 Halted 0 ms 0 KB -