D. Three Logos

Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area.

Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no empty space left. When you put a logo on the billboard, you should rotate it so that the sides were parallel to the sides of the billboard.

Your task is to determine if it is possible to put the logos of all the three companies on some square billboard without breaking any of the described rules.

Input

The first line of the input contains six positive integers x1, y1, x2, y2, x3, y3 (1 ≤ x1, y1, x2, y2, x3, y3 ≤ 100), where xi and yi determine the length and width of the logo of the i-th company respectively.

Output

If it is impossible to place all the three logos on a square shield, print a single integer "-1" (without the quotes).

If it is possible, print in the first line the length of a side of square n, where you can place all the three logos. Each of the next n lines should contain n uppercase English letters "A", "B" or "C". The sets of the same letters should form solid rectangles, provided that:

  • the sizes of the rectangle composed from letters "A" should be equal to the sizes of the logo of the first company,
  • the sizes of the rectangle composed from letters "B" should be equal to the sizes of the logo of the second company,
  • the sizes of the rectangle composed from letters "C" should be equal to the sizes of the logo of the third company,

Note that the logos of the companies can be rotated for printing on the billboard. The billboard mustn't have any empty space. If a square billboard can be filled with the logos in multiple ways, you are allowed to print any of them.

See the samples to better understand the statement.

Sample test(s)
input
5 1 2 5 5 2
output
5
AAAAA
BBBBB
BBBBB
CCCCC
CCCCC
input
4 4 2 6 4 2
output
6
BBBBBB
BBBBBB
AAAACC
AAAACC
AAAACC
AAAACC
///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mod 1000000007
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//**************************************** int main()
{ int x1=read(),y1=read(),x2=read(),y2=read(),x3=read(),y3=read();
if(x1<y1)swap(x1,y1);
if(x2<y2)swap(x2,y2);
if(x3<y3)swap(x3,y3);
int L=max(x1,max(x2,x3));
if(L*L!=x1*y1+x2*y2+x3*y3){cout<<-<<endl;return ;}
if(L==x1&&L==x2&&L==x3){
cout<<L<<endl;
FOR(i,,y1){FOR(j,,L)
{
cout<<"A";
}
cout<<endl;}
FOR(i,,y2){FOR(j,,L)
{
cout<<"B";
}
cout<<endl;}
FOR(i,,y3){FOR(j,,L)
{
cout<<"C";
}
cout<<endl;} }
else {
if(x1==L)
{
if (x2==L-y1)swap(x2,y2);if(x3==L-y1)swap(x3,y3);
if(x2+x3!=L||y1+y2!=L||y2!=y3){
cout<<-<<endl;return ;
}
cout<<L<<endl;
FOR(i,,L-y1){
FOR(j,,x2)cout<<"B";
FOR(j,,x3)cout<<"C";
cout<<endl; }
FOR(i,,y1){FOR(j,,L){
cout<<"A";
}cout<<endl;}
}
else if(x2==L)
{
if (x1==L-y2)swap(x1,y1);if (x3==L-y2)swap(x3,y3);
if(x1+x3!=L||y2+y3!=L||y1!=y3){
cout<<-<<endl;return ;
}
cout<<L<<endl;
FOR(i,,L-y2){
FOR(j,,x1)cout<<"A";
FOR(j,,x3)cout<<"C";
cout<<endl; }
FOR(i,,y2){FOR(j,,L){
cout<<"B";
}cout<<endl;}
}else if(x3==L)
{
if (x2==L-y3)swap(x2,y2);if (x1==L-y3)swap(x1,y1);
if(x2+x1!=L||y3+y2!=L||y2!=y1){
cout<<-<<endl;return ;
}
cout<<L<<endl;
FOR(i,,L-y3){
FOR(j,,x1)cout<<"A";
FOR(j,,x2)cout<<"B";
cout<<endl; }
FOR(i,,y3){FOR(j,,L){
cout<<"C";
}cout<<endl;}
}
}
return ;
}

模拟

Codeforces Round #322 (Div. 2) D. Three Logos 模拟的更多相关文章

  1. Codeforces Round #322 (Div. 2) D. Three Logos 暴力

    D. Three Logos Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/problem ...

  2. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  3. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  5. Codeforces Round #322 (Div. 2) C. Developing Skills 优先队列

    C. Developing Skills Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  6. Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题

    B. Luxurious Houses Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/pr ...

  7. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  8. Codeforces Round #322 (Div. 2)

    水 A - Vasya the Hipster /************************************************ * Author :Running_Time * C ...

  9. Codeforces Round #322 (Div. 2) —— F. Zublicanes and Mumocrates

    It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The ...

随机推荐

  1. mybatis generator 覆盖xml文件

    mybatis generator默认采用追加方式生成,所以我们如果要重新生成代码的时候那么要先删除原来的文件. 解决办法: 1:创建一个自定义补丁类. OverwriteXmlPlugin.java ...

  2. Java中的JVM的内存结构

    Java的虚拟机自身结构图: JVM内存结构主要包括两个子系统和两个组件.两个子系统分别是Classloader子系统和Executionengine(执行引擎)子系统:两个组件分别是Runtimed ...

  3. 题解 洛谷P2147/BZOJ2049【[SDOI2008]洞穴勘测】

    Link-Cut-Tree的模板题啊......(听说还可以用其他的方法做,不管了,直接上LCT) 没有要求维护点权,只需要维护点的连通性即可. 就是朴素的LCT,居然还不要pushup. 感觉有些不 ...

  4. CentOS7-Git安装以及使用

    2018-09-14 Git安装 在bash终端中输入命令sudo yum install git回车. (出乎意料的顺利) 在随后出现的交互式对话中输入y即可. 随后,当任务执行完后,在bash中键 ...

  5. 笔试算法题(48):简介 - A*搜索算法(A Star Search Algorithm)

    A*搜索算法(A Star Search Algorithm) A*算法主要用于在二维平面上寻找两个点之间的最短路径.在从起始点到目标点的过程中有很多个状态空间,DFS和BFS没有任何启发策略所以穷举 ...

  6. laravel学习笔记3--高级

    一.artisan 1.基本使用: 1.1.查看基本命令: php artisan 1.2.查看具体命名的使用: php artisan help migrate 1.3.创建控制器: php art ...

  7. I - DFS(依然是漫水填充)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  8. POJ-2239 Selecting Courses,三维邻接矩阵实现,钻数据空子。

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K       Description It is well known that ...

  9. bzoj4553 [Tjoi2016&Heoi2016]序列 树状数组(区间最大值)+cqd

    [Tjoi2016&Heoi2016]序列 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1006  Solved: 464[Submit][ ...

  10. 2017年12月14日 一个Java开发的Python之路----------------(二)

    说一个收获最大的,就是这个关闭流对象 之前写java读取文件的时候,最后往往要关闭流对象,以前我一直不明白,为什么,我不使用.close()方法,文件也可以读取成功,总感觉没有什么意义 原来是因为,这 ...