Submission #4022649
Source Code Expand
#include <stdio.h>
#define HEIGHT_MAX 101 /* チョコの最大縦マス(配列を1オリジンとするため+1) */
#define WIDTH_MAX 101 /* チョコの最大横マス(配列を1オリジンとするため+1) */
typedef unsigned char U1;
typedef unsigned short U2;
typedef unsigned long U4;
typedef signed char S1;
typedef signed short S2;
typedef signed long S4;
/********************************************************************************/
/* 関数名 | initData */
/* 機能仕様 | 入力用配列の初期化 */
/* 引数 | u2InpBlackData 黒チョコ濃度格納配列 */
/* | u2InpWhiteData 白チョコ濃度格納配列 */
/* 戻り値 | 無し */
/* 備考 | 無し */
/********************************************************************************/
void initData(U2 u2InpBlackData[HEIGHT_MAX][WIDTH_MAX],U2 u2InpWhiteData[HEIGHT_MAX][WIDTH_MAX])
{
U1 u1CntHeight;
U1 u1CntWidth;
for(u1CntHeight = 0; u1CntHeight < HEIGHT_MAX; u1CntHeight++ )
{
for(u1CntWidth = 0; u1CntWidth < WIDTH_MAX; u1CntWidth++ )
{
u2InpBlackData[u1CntHeight][u1CntWidth] = 0;
u2InpWhiteData[u1CntHeight][u1CntWidth] = 0;
}
}
}
/********************************************************************************/
/* 関数名 | inputData */
/* 機能仕様 | データ入力 */
/* 引数 | u1Height チョコの縦マス */
/* | u1Width チョコの横マス */
/* | u2InpBlackData 黒チョコ濃度格納配列 */
/* | u2InpWhiteData 白チョコ濃度格納配列 */
/* 戻り値 | 無し */
/* 備考 | 無し */
/********************************************************************************/
void inputData(U1 *u1Height,U1 *u1Width,U2 u2InpBlackData[HEIGHT_MAX][WIDTH_MAX],U2 u2InpWhiteData[HEIGHT_MAX][WIDTH_MAX])
{
int input;
U1 u1CntHeight;
U1 u1CntWidth;
U1 u1TmpDensity;
scanf("%d",&input);
*u1Height = (U1)input;
scanf("%d",&input);
*u1Width = (U1)input;
for(u1CntHeight = 1; u1CntHeight <= *u1Height; u1CntHeight++ )
{
for(u1CntWidth = 1; u1CntWidth <= *u1Width; u1CntWidth++ )
{
scanf("%d",&input);
u1TmpDensity = (U1)input;
/* 黒白のチョコレートの濃度をそれぞれ別々の配列に格納する */
/* 異なるチョコレートの濃度は0とする */
if((u1CntHeight % 2) == 0)
{
if((u1CntWidth % 2) == 0)
{
u2InpBlackData[u1CntHeight][u1CntWidth] = u1TmpDensity;
u2InpWhiteData[u1CntHeight][u1CntWidth] = 0;
}
else
{
u2InpBlackData[u1CntHeight][u1CntWidth] = 0;
u2InpWhiteData[u1CntHeight][u1CntWidth] = u1TmpDensity;
}
}
else
{
if((u1CntWidth % 2) == 0)
{
u2InpBlackData[u1CntHeight][u1CntWidth] = 0;
u2InpWhiteData[u1CntHeight][u1CntWidth] = u1TmpDensity;
}
else
{
u2InpBlackData[u1CntHeight][u1CntWidth] = u1TmpDensity;
u2InpWhiteData[u1CntHeight][u1CntWidth] = 0;
}
}
}
}
}
/********************************************************************************/
/* 関数名 | calcCumSum */
/* 機能仕様 | 累積和計算 */
/* 引数 | u1Height チョコの縦マス */
/* | u1Width チョコの横マス */
/* | u2InputData チョコ濃度格納配列 */
/* | u2CumData 累積和格納変数 */
/* 戻り値 | 無し */
/* 備考 | 無し */
/********************************************************************************/
void calcCumSum(U1 u1Height,U1 u1Width,U2 u2InputData[HEIGHT_MAX][WIDTH_MAX],U2 u2CumData[HEIGHT_MAX][WIDTH_MAX])
{
U1 u1CntHeight;
U1 u1CntWidth;
for(u1CntHeight = 0; u1CntHeight < HEIGHT_MAX; u1CntHeight++ )
{
for(u1CntWidth = 0; u1CntWidth < WIDTH_MAX; u1CntWidth++ )
{
u2CumData[u1CntHeight][u1CntWidth] = u2InputData[u1CntHeight][u1CntWidth];
}
}
/* 横の濃度に対して累積和を計算する */
for(u1CntHeight = 0; u1CntHeight <= u1Height; u1CntHeight++ )
{
for(u1CntWidth = 1; u1CntWidth <= u1Width; u1CntWidth++ )
{
u2CumData[u1CntHeight][u1CntWidth] += u2CumData[u1CntHeight][u1CntWidth - 1];
}
}
/* 縦の濃度に対して累積和を計算する */
for(u1CntHeight = 1; u1CntHeight <= u1Height; u1CntHeight++ )
{
for(u1CntWidth = 0; u1CntWidth <= u1Width; u1CntWidth++ )
{
u2CumData[u1CntHeight][u1CntWidth] += u2CumData[u1CntHeight - 1][u1CntWidth];
}
}
}
/********************************************************************************/
/* 関数名 | getMaxChcMass */
/* 機能仕様 | 最大のチョコのマスを取得 */
/* 引数 | u1Height チョコの縦マス */
/* | u1Width チョコの横マス */
/* | u2CumBlack 黒チョコ累積和格納配列 */
/* | u2CumWhite 白チョコ累積和格納配列 */
/* 戻り値 | 最大マス */
/* 備考 | 無し */
/********************************************************************************/
U2 getMaxChcMass(U1 u1Height,U1 u1Width,U2 u2CumBlack[HEIGHT_MAX][WIDTH_MAX],U2 u2CumWhite[HEIGHT_MAX][WIDTH_MAX])
{
U1 u1CntHeight;
U1 u1CntWidth;
U1 u1TgtHeight;
U1 u1TgtWidth;
U2 u2BlackSum;
U2 u2WhiteSum;
U2 u2ChocoMass;
U2 u2TmpMass;
u2ChocoMass = 0;
/* チョコの範囲の左上を走査 */
for(u1CntHeight = 1; u1CntHeight <= u1Height; u1CntHeight++ )
{
for(u1CntWidth = 1; u1CntWidth <= u1Width; u1CntWidth++ )
{
/* チョコの範囲の右下を走査 */
for(u1TgtHeight = u1CntHeight; u1TgtHeight <= u1Height; u1TgtHeight++ )
{
for(u1TgtWidth = u1CntWidth; u1TgtWidth <= u1Width; u1TgtWidth++ )
{
/*
|-|-----------|
|A| B|
|-|-----------|
| | |
| | |
|C| D|
|-|-----------|
A,B,C,Dはそれぞれ、区切られた範囲の累積和
Dの範囲の濃度合計は、
累積和のD-(B+D)+Aを計算することで求められる。
*/
u2BlackSum = u2CumBlack[u1TgtHeight][u1TgtWidth]
- (u2CumBlack[u1TgtHeight][u1CntWidth - 1] + u2CumBlack[u1CntHeight - 1][u1TgtWidth])
+ u2CumBlack[u1CntHeight - 1][u1CntWidth - 1];
u2WhiteSum = u2CumWhite[u1TgtHeight][u1TgtWidth]
- (u2CumWhite[u1TgtHeight][u1CntWidth - 1] + u2CumWhite[u1CntHeight - 1][u1TgtWidth])
+ u2CumWhite[u1CntHeight - 1][u1CntWidth - 1];
if(u2BlackSum == u2WhiteSum)
{
u2TmpMass = (u1TgtHeight - u1CntHeight + 1) * (u1TgtWidth - u1CntWidth + 1);
if(u2ChocoMass < u2TmpMass)
{
u2ChocoMass = u2TmpMass;
}
}
}
}
}
}
return u2ChocoMass;
}
/********************************************************************************/
/* 関数名 | getMaxChcMass */
/* 機能仕様 | チョコマスの表示 */
/* 引数 | u2ChocoMass チョコマス */
/* 戻り値 | 最大マス */
/* 備考 | 無し */
/********************************************************************************/
void outputChocoMass(U2 u2ChocoMass)
{
printf("%d\n",u2ChocoMass);
}
/********************************************************************************/
/* 関数名 | main */
/* 機能仕様 | main分 */
/* 引数 | 無し */
/* 戻り値 | 無し */
/* 備考 | 無し */
/********************************************************************************/
int main(void)
{
U1 u1Height;
U1 u1Width;
U2 u2ChocoMass;
U2 u2ChocoBlack[HEIGHT_MAX][WIDTH_MAX];
U2 u2ChocoWhite[HEIGHT_MAX][WIDTH_MAX];
U2 u2CumChcBlack[HEIGHT_MAX][WIDTH_MAX];
U2 u2CumChcWhite[HEIGHT_MAX][WIDTH_MAX];
/* 初期化部 */
initData(u2ChocoBlack,u2ChocoWhite);
/* 入力部 */
inputData(&u1Height,&u1Width,u2ChocoBlack,u2ChocoWhite);
/* 制御部 */
calcCumSum(u1Height,u1Width,u2ChocoBlack,u2CumChcBlack);
calcCumSum(u1Height,u1Width,u2ChocoWhite,u2CumChcWhite);
u2ChocoMass = getMaxChcMass(u1Height,u1Width,u2CumChcBlack,u2CumChcWhite);
/* 出力部 */
outputChocoMass(u2ChocoMass);
}
Submission Info
Submission Time
2019-01-16 10:09:06+0900
Task
B - チョコレート
User
yamaneeeen
Language
C (GCC 5.4.1)
Score
100
Code Size
11461 Byte
Status
AC
Exec Time
57 ms
Memory
256 KB
Compile Error
./Main.c: In function ‘inputData’:
./Main.c:52:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&input);
^
./Main.c:55:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&input);
^
./Main.c:62:13: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&input);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
Set Name
Test Cases
Sample
subtask0_sample-01.txt, subtask0_sample-02.txt, subtask0_sample-03.txt, subtask0_sample-04.txt, subtask0_sample-05.txt
All
subtask0_sample-01.txt, subtask0_sample-02.txt, subtask0_sample-03.txt, subtask0_sample-04.txt, subtask0_sample-05.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt
Case Name
Status
Exec Time
Memory
subtask0_sample-01.txt
AC
1 ms
256 KB
subtask0_sample-02.txt
AC
1 ms
256 KB
subtask0_sample-03.txt
AC
1 ms
256 KB
subtask0_sample-04.txt
AC
1 ms
256 KB
subtask0_sample-05.txt
AC
1 ms
256 KB
subtask1_01.txt
AC
1 ms
256 KB
subtask1_02.txt
AC
1 ms
256 KB
subtask1_03.txt
AC
1 ms
256 KB
subtask1_04.txt
AC
1 ms
256 KB
subtask1_05.txt
AC
1 ms
256 KB
subtask1_06.txt
AC
1 ms
256 KB
subtask1_07.txt
AC
1 ms
256 KB
subtask1_08.txt
AC
1 ms
256 KB
subtask1_09.txt
AC
54 ms
256 KB
subtask1_10.txt
AC
9 ms
256 KB
subtask1_11.txt
AC
42 ms
256 KB
subtask1_12.txt
AC
42 ms
256 KB
subtask1_13.txt
AC
42 ms
256 KB
subtask1_14.txt
AC
55 ms
256 KB
subtask1_15.txt
AC
55 ms
256 KB
subtask1_16.txt
AC
41 ms
256 KB
subtask1_17.txt
AC
44 ms
256 KB
subtask1_18.txt
AC
1 ms
256 KB
subtask1_19.txt
AC
1 ms
256 KB
subtask1_20.txt
AC
57 ms
256 KB