Language: C++

/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 505;


// class complex {
//     long double image, real;
// public:
//     long double getImage() {
//         return image;
//     }
//     long double getReal() {
//         return real;
//     }

// };


int n;
int a[MAXN][MAXN];
long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   // read(FILENAME);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - 1; j++) {
            cin >> a[i][j + (i <= j)];
        }
    }
    for (int i = 1; i <= n; i++) {
        long long sum1 = 0, sum2 = 0;
        for (int j = i; j <= n; j++) {
            sum1 += a[i][j];
            sum2 += a[j][i];
            s1[i][j] = s1[i - 1][j] + sum1;
            s2[i][j] = s2[i - 1][j] + sum2;
        } 
    }
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            dp[i][j] = 1e18;
        }
    }
    for (int i = 2; i <= n; i++) {
        dp[i][1] = s1[i - 1][i - 1];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++) {
            for (int x = i + 1; x <= n; x++) {
                long long sum1 = s1[x - 1][x - 1] - s1[i - 1][x - 1];
                long long sum2 = s2[i - 1][n] - s2[j - 1][n] - s2[i - 1][x - 1] + s2[j - 1][x - 1];
                chkmin(dp[x][i], dp[i][j] + sum1 + sum2);
            }
        }
    }
    long long ans = s1[n][n];
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++) {
            chkmin(ans, dp[i][j] + s1[n][n] - s1[i - 1][n]);
        }
    }
    cout << ans << endl;
    return 0;
}
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 505;


// class complex {
//     long double image, real;
// public:
//     long double getImage() {
//         return image;
//     }
//     long double getReal() {
//         return real;
//     }

// };


int n;
int a[MAXN][MAXN];
long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   // read(FILENAME);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - 1; j++) {
            cin >> a[i][j + (i <= j)];
        }
    }
    for (int i = 1; i <= n; i++) {
        long long sum1 = 0, sum2 = 0;
        for (int j = i; j <= n; j++) {
            sum1 += a[i][j];
            sum2 += a[j][i];
            s1[i][j] = s1[i - 1][j] + sum1;
            s2[i][j] = s2[i - 1][j] + sum2;
        } 
    }
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            dp[i][j] = 1e18;
        }
    }
    for (int i = 2; i <= n; i++) {
        dp[i][1] = s1[i - 1][i - 1];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++) {
            for (int x = i + 1; x <= n; x++) {
                long long sum1 = s1[x - 1][x - 1] - s1[i - 1][x - 1];
                long long sum2 = s2[i - 1][n] - s2[j - 1][n] - s2[i - 1][x - 1] + s2[j - 1][x - 1];
                chkmin(dp[x][i], dp[i][j] + sum1 + sum2);
            }
        }
    }
    long long ans = s1[n][n];
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i - 1; j++) {
            chkmin(ans, dp[i][j] + s1[n][n] - s1[i - 1][n]);
        }
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:165:47: error: redefinition of 'template<class T1, class T2> void chkmin(T1&, T2)'
  165 | template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
      |                                               ^~~~~~
a.cc:41:47: note: 'template<class T1, class T2> void chkmin(T1&, T2)' previously declared here
   41 | template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
      |                                               ^~~~~~
a.cc:166:47: error: redefinition of 'template<class T1, class T2> void chkmax(T1&, T2)'
  166 | template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
      |                                               ^~~~~~
a.cc:42:47: note: 'template<class T1, class T2> void chkmax(T1&, T2)' previously declared here
   42 | template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
      |                                               ^~~~~~
a.cc:181:14: error: redefinition of 'const std::string FILENAME'
  181 | const string FILENAME = "input";
      |              ^~~~~~~~
a.cc:57:14: note: 'const std::string FILENAME' previously declared here
   57 | const string FILENAME = "input";
      |              ^~~~~~~~
a.cc:182:11: error: redefinition of 'const int MAXN'
  182 | const int MAXN = 505;
      |           ^~~~
a.cc:58:11: note: 'const int MAXN' previously defined here
   58 | const int MAXN = 505;
      |           ^~~~
a.cc:198:5: error: redefinition of 'int n'
  198 | int n;
      |     ^
a.cc:74:5: note: 'int n' previously declared here
   74 | int n;
      |     ^
a.cc:199:5: error: redefinition of 'int a [505][505]'
  199 | int a[MAXN][MAXN];
      |     ^
a.cc:75:5: note: 'int a [505][505]' previously declared here
   75 | int a[MAXN][MAXN];
      |     ^
a.cc:200:11: error: redefinition of 'long long int s1 [505][505]'
  200 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |           ^~
a.cc:76:11: note: 'long long int s1 [505][505]' previously declared here
   76 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |           ^~
a.cc:200:27: error: redefinition of 'long long int s2 [505][505]'
  200 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |                           ^~
a.cc:76:27: note: 'long long int s2 [505][505]' previously declared here
   76 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |                           ^~
a.cc:200:43: error: redefinition of 'long long int dp [505][505]'
  200 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |                                           ^~
a.cc:76:43: note: 'long long int dp [505][505]' previously declared here
   76 | long long s1[MAXN][MAXN], s2[MAXN][MAXN], dp[MAXN][MAXN];
      |                                           ^~
a.cc:203:5: error: redefinition of 'int main()'
  203 | int main() {
      |     ^~~~
a.cc:79:5: note: 'int main()' previously defined here
   79 | int main() {
      |     ^~~~