PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000165. Bảng nhị phân cân bằng (Grid-00100)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bảng nhị phân cân bằng (Grid-00100)
Grid-00100
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Construct an binary grid with exactly ones. Let and be its row and column sums. Minimize . Print the minimum score and any grid attaining it.
Input
One line contains integers .
Output
Print the minimum possible , followed by rows of exactly characters 0 or 1, without spaces.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2 2
Output
0
10
01
Explanation
Place the two ones at and . Both row sums and both column sums are , giving . A sum of squares cannot be negative, so the score is optimal.