#include <stdio.h>
#include <stdlib.h>
// 必要な変数を追加してもOK
int main() {
int i, j;
int a, b;
int **mat;
// 行数と列数を入力
// 2次元配列の動的確保
mat
= (int**)malloc(sizeof(int*) * a
); // 行のためのメモリ確保 if (mat == NULL) {
printf("Memory allocation failed!\n"); return 1;
}
// 各行に対して列のためのメモリ確保
for (i = 0; i < a; i++) {
mat
[i
] = (int*)malloc(sizeof(int) * b
); // 列のメモリ確保 if (mat[i] == NULL) {
printf("Memory allocation failed!\n"); return 1;
}
}
// 2次元配列に値を代入
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
scanf("%d", &mat
[i
][j
]); // 各要素に値を入力 }
}
// 配列の内容を表示
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
}
}
// メモリの解放
for (i = 0; i < a; i++) {
free(mat
[i
]); // 各行に対して解放 }
free(mat
); // 行のポインタ自体を解放
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCi8vIOW/heimgeOBquWkieaVsOOCkui/veWKoOOBl+OBpuOCgk9LCgppbnQgbWFpbigpIHsKICAgIGludCBpLCBqOwogICAgaW50IGEsIGI7CiAgICBpbnQgKiptYXQ7CiAgICAKICAgIC8vIOihjOaVsOOBqOWIl+aVsOOCkuWFpeWKmwogICAgc2NhbmYoIiVkICVkIiwgJmEsICZiKTsKCiAgICAvLyAy5qyh5YWD6YWN5YiX44Gu5YuV55qE56K65L+dCiAgICBtYXQgPSAoaW50KiopbWFsbG9jKHNpemVvZihpbnQqKSAqIGEpOyAgLy8g6KGM44Gu44Gf44KB44Gu44Oh44Oi44Oq56K65L+dCiAgICBpZiAobWF0ID09IE5VTEwpIHsKICAgICAgICBwcmludGYoIk1lbW9yeSBhbGxvY2F0aW9uIGZhaWxlZCFcbiIpOwogICAgICAgIHJldHVybiAxOwogICAgfQoKICAgIC8vIOWQhOihjOOBq+WvvuOBl+OBpuWIl+OBruOBn+OCgeOBruODoeODouODqueiuuS/nQogICAgZm9yIChpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIG1hdFtpXSA9IChpbnQqKW1hbGxvYyhzaXplb2YoaW50KSAqIGIpOyAgLy8g5YiX44Gu44Oh44Oi44Oq56K65L+dCiAgICAgICAgaWYgKG1hdFtpXSA9PSBOVUxMKSB7CiAgICAgICAgICAgIHByaW50ZigiTWVtb3J5IGFsbG9jYXRpb24gZmFpbGVkIVxuIik7CiAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgIH0KCiAgICAvLyAy5qyh5YWD6YWN5YiX44Gr5YCk44KS5Luj5YWlCiAgICBmb3IgKGkgPSAwOyBpIDwgYTsgaSsrKSB7CiAgICAgICAgZm9yIChqID0gMDsgaiA8IGI7IGorKykgewogICAgICAgICAgICBzY2FuZigiJWQiLCAmbWF0W2ldW2pdKTsgIC8vIOWQhOimgee0oOOBq+WApOOCkuWFpeWKmwogICAgICAgIH0KICAgIH0KCiAgICAvLyDphY3liJfjga7lhoXlrrnjgpLooajnpLoKICAgIGZvciAoaSA9IDA7IGkgPCBhOyBpKyspIHsKICAgICAgICBmb3IgKGogPSAwOyBqIDwgYjsgaisrKSB7CiAgICAgICAgICAgIHByaW50ZigiJWQgIiwgbWF0W2ldW2pdKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQoKICAgIC8vIOODoeODouODquOBruino+aUvgogICAgZm9yIChpID0gMDsgaSA8IGE7IGkrKykgewogICAgICAgIGZyZWUobWF0W2ldKTsgIC8vIOWQhOihjOOBq+WvvuOBl+OBpuino+aUvgogICAgfQogICAgZnJlZShtYXQpOyAgLy8g6KGM44Gu44Od44Kk44Oz44K/6Ieq5L2T44KS6Kej5pS+CgogICAgcmV0dXJuIDA7Cn0K