Language: C++

include <cstdlib>
#include <string.h>
#include <iostream>
#include <string>

// ciada's distribution parameter
int cicadaNum[50][50];

int checkPattern(int num, int max, int total)
{
    int count = 0;

    for (int i = 0; i < total; i++)
    {
        int tmp = num & (0x1 << i);
        if (tmp != 0){
            ++count;
        }
    }

    if (max == count) {
        return 0;
    }
    return -1;
}

int cicadaSum(int pattern, int operationNum, int high, int wide)
{
    int iHigh = high - 1;
    int iWide = wide - 1;
    int tmp = cicadaNum[iHigh][iWide];
    int sum = tmp;
    //printf("%d ", tmp);
    for (int i = 0; i < operationNum; i++) {
        int op = (pattern >> i) & 0x1;
        if (op == 1) {
            tmp = cicadaNum[iHigh][--iWide];
            sum += tmp;
            //printf("%d ", tmp);
        }
        else {
            tmp = cicadaNum[--iHigh][iWide];
            sum += tmp;
            //printf("%d ", tmp);
        }
    }
    //printf("=%d\n", sum);
    return sum;
}

int main()
{
    memset(&cicadaNum[0][0],0, sizeof(cicadaNum));

    int high, wide;
    std::cin >> high >> wide;

    // operation number
    int operationNum = high + wide - 2;

    // get ciada's distribution
    std::string line;
    for (int iHigh = 0; iHigh < high; iHigh++) {
        std::cin >> line;
        for (int iWide = 0; iWide < wide; iWide++) {
            char c = line[iWide];
            cicadaNum[iHigh][iWide] = atoi(&c);
        }
    }

    // make scanning pattern (sample 101010... 1 is right. 0 is down)
    int pattern = 0;
    for (int i = 0; i < operationNum; i++) {
        pattern |= 0x1 << i;
    }

    //  calculate minimum number of encounter
    int minNum = 9*50*2;
    for (int i = 0; i < pattern; i++) {

        // all pattern check 
        if (checkPattern(i, wide - 1, high + wide - 2) == 0){
            int tmp = cicadaSum(i, operationNum, high, wide);
            if (tmp < minNum) {
                minNum = tmp;
            }
        }
    }

    std::cout << minNum << std::endl;

    return 0;
}




Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <cstdlib>
      | ^~~~~~~
In file included from /usr/include/c++/14/cwchar:44,
                 from /usr/include/c++/14/bits/postypes.h:40,
                 from /usr/include/c++/14/iosfwd:42,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/wchar.h:104:59: error: 'size_t' has not been declared
  104 |                          const wchar_t *__restrict __src, size_t __n)
      |                                                           ^~~~~~
/usr/include/wchar.h:109:8: error: 'size_t' does not name a type
  109 | extern size_t wcslcpy (wchar_t *__restrict __dest,
      |        ^~~~~~
/usr/include/wchar.h:58:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
   57 | # include <bits/types/FILE.h>
  +++ |+#include <cstddef>
   58 | #endif
/usr/include/wchar.h:115:8: error: 'size_t' does not name a type
  115 | extern size_t wcslcat (wchar_t *__restrict __dest,
      |        ^~~~~~
/usr/include/wchar.h:115:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:126:59: error: 'size_t' has not been declared
  126 |                          const wchar_t *__restrict __src, size_t __n)
      |                                                           ^~~~~~
/usr/include/wchar.h:133:63: error: 'size_t' has not been declared
  133 | extern int wcsncmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
      |                                                               ^~~~~~
/usr/include/wchar.h:142:25: error: 'size_t' has not been declared
  142 |                         size_t __n) __THROW;
      |                         ^~~~~~
/usr/include/wchar.h:147:26: error: 'locale_t' has not been declared
  147 |                          locale_t __loc) __THROW;
      |                          ^~~~~~~~
/usr/include/wchar.h:150:27: error: 'size_t' has not been declared
  150 |                           size_t __n, locale_t __loc) __THROW;
      |                           ^~~~~~
/usr/include/wchar.h:150:39: error: 'locale_t' has not been declared
  150 |                           size_t __n, locale_t __loc) __THROW;
      |                                       ^~~~~~~~
/usr/include/wchar.h:159:8: error: 'size_t' does not name a type
  159 | extern size_t wcsxfrm (wchar_t *__restrict __s1,
      |        ^~~~~~
/usr/include/wchar.h:159:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:169:23: error: 'locale_t' has not been declared
  169 |                       locale_t __loc) __THROW;
      |                       ^~~~~~~~
/usr/include/wchar.h:174:8: error: 'size_t' does not name a type
  174 | extern size_t wcsxfrm_l (wchar_t *__s1, const wchar_t *__s2,
      |        ^~~~~~
/usr/include/wchar.h:174:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:212:8: error: 'size_t' does not name a type
  212 | extern size_t wcscspn (const wchar_t *__wcs, const wchar_t *__reject)
      |        ^~~~~~
/usr/include/wchar.h:212:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:216:8: error: 'size_t' does not name a type
  216 | extern size_t wcsspn (const wchar_t *__wcs, const wchar_t *__accept)
      |        ^~~~~~
/usr/include/wchar.h:216:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:247:8: error: 'size_t' does not name a type
  247 | extern size_t wcslen (const wchar_t *__s) __THROW __attribute_pure__;
      |        ^~~~~~
/usr/include/wchar.h:247:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:265:8: error: 'size_t' does not name a type
  265 | extern size_t wcsnlen (const wchar_t *__s, size_t __maxlen)
      |        ^~~~~~
/usr/include/wchar.h:265:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:272:59: error: 'size_t' has not been declared
  272 | extern "C++" wchar_t *wmemchr (wchar_t *__s, wchar_t __c, size_t __n)
      |                                                           ^~~~~~
/usr/include/wchar.h:275:38: error: 'size_t' has not been declared
  275 |                                      size_t __n)
      |                                      ^~~~~~
/usr/include/wchar.h:283:63: error: 'size_t' has not been declared
  283 | extern int wmemcmp (const wchar_t *__s1, const wchar_t *__s2, size_t __n)
      |                                                               ^~~~~~
/usr/include/wchar.h:288:58: error: 'size_t' has not been declared
  288 |                          const wchar_t *__restrict __s2, size_t __n) __THROW;
      |                                                          ^~~~~~
/usr/include/wchar.h:292:63: error: 'size_t' has not been declared
  292 | extern wchar_t *wmemmove (wchar_t *__s1, const wchar_t *__s2, size_t __n)
      |                                                               ^~~~~~
/usr/include/wchar.h:296:53: error: 'size_t' has not been declared
  296 | extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW;
      |                                                     ^~~~~~
/usr/include/wchar.h:302:59: error: 'size_t' has not been declared
  302 |                           const wchar_t *__restrict __s2, size_t __n)
      |                                                           ^~~~~~
/usr/include/wchar.h:321:8: error: 'size_t' does not name a type
  321 | extern size_t mbrtowc (wchar_t *__restrict __pwc,
      |        ^~~~~~
/usr/include/wchar.h:321:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:326:8: error: 'size_t' does not name a type
  326 | extern size_t wcrtomb (char *__restrict __s, wchar_t __wc,
      |        ^~~~~~
/usr/include/wchar.h:326:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:330:8: error: 'size_t' does not name a type
  330 | extern size_t __mbrlen (const char *__restrict __s, size_t __n,
      |        ^~~~~~
/usr/include/wchar.h:330:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:332:8: error: 'size_t' does not name a type
  332 | extern size_t mbrlen (const char *__restrict __s, size_t __n,
      |        ^~~~~~
/usr/include/wchar.h:332:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:362:8: error: 'size_t' does not name a type
  362 | extern size_t mbsrtowcs (wchar_t *__restrict __dst,
      |        ^~~~~~
/usr/include/wchar.h:362:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:368:8: error: 'size_t' does not name a type
  368 | extern size_t wcsrtombs (char *__restrict __dst,
      |        ^~~~~~
/usr/include/wchar.h:368:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:376:8: error: 'size_t' does not name a type
  376 | extern size_t mbsnrtowcs (wchar_t *__restrict __dst,
      |        ^~~~~~
/usr/include/wchar.h:376:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:382:8: error: 'size_t' does not name a type
  382 | extern size_t wcsnrtombs (char *__restrict __dst,
      |        ^~~~~~
/usr/include/wchar.h:382:8: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
/usr/include/wchar.h:396:42: error: 'size_t' has not been declared
  396 | extern int wcswidth (const wchar_t *__s, size_t __n) __THROW;
      |                                          ^~~~~~
/usr/include/wchar.h:563:27: error: 'locale_t' has not been declared
  563 |                           locale_t __loc) __THROW;
      |                           ^~~~~~~~
/usr/include/wchar.h:567:49: error: 'locale_t' has not been declared
  567 |                                     int __base, locale_t __loc) __THROW;
      |                                                 ^~~~~~~~
/usr/include/wchar.h:572:45: error: 'locale_t' has not been declared
  572 |                                 int __base, locale_t __loc) __THROW;
      |                                             ^~~~~~~~
/usr/include/wchar.h:577:55: error: 'locale_t' has not been declared
  577 |                                           int __base, locale_t __loc)
      |                                                       ^~~~~~~~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/string.h:26,
                 from a.cc:2:
/usr/include/wchar.h:584:17: error: 'locale_t' has not been declared
  584 | extern long int __REDIRECT_NTH (wcstol_l, (const wchar_t *__restrict __nptr,
      |                 ^~~~~~~~~~~~~~
/usr/include/wchar.h:588:26: error: 'locale_t' has not been declared
  588 | extern unsigned long int __REDIRECT_NTH (wcstoul_l,
      |                          ^~~~~~~~~~~~~~
/usr/include/wchar.h:594:22: error: 'locale_t' has not been declared
  594 | extern long long int __REDIRECT_NTH (wcstoll_l,
      |                      ^~~~~~~~~~~~~~
/usr/include/wchar.h:600:31: error: 'locale_t' has not been declared
  600 | extern unsigned long long int __REDIRECT_NTH (wcstoull_l,
      |                               ^~~~~~~~~~~~~~
/usr/include/wchar.h:631:56: error: 'locale_t' has not been declared
  631 |                         wchar_t **__restrict __endptr, locale_t __loc)
      |