Language: C++

#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const ll INF = 1e18;
const int MAXN = 505;

int n;
ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];

ll getVal1(int a,int b,int c,int d){
	return sum1[b][d] - (c == 0 ? 0 : sum1[b][c - 1]) - (a == 0 ? 0 : sum1[a - 1][d]) + (a == 0 || c == 0 ? 0 : sum1[a - 1][c - 1]);
}

ll getVal2(int a,int b,int c,int d){
	return sum2[b][d] - (c == 0 ? 0 : sum2[b][c - 1]) - (a == 0 ? 0 : sum2[a - 1][d]) + (a == 0 || c == 0 ? 0 : sum2[a - 1][c - 1]);
}

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			if(i != j)
			    scanf("%d",&w[i][j]);
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++)
		    sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1] + w[i][j];
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++)
		    sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1] + (i < j ? w[i][j] : 0);
	}
	for(int i = 1;i <= n;i++){
		f[i][1] = getVal2(0,i,0,i);
		for(int j = 2;j <= i;j++){
			f[i][j] = INF;
			for(int k = 1;k < j;k++)
				f[i][j] = min(f[i][j],f[j - 1][k] + getVal2(j,i,j,i) + getVal1(j,i,0,k - 1));
		}
	}
	ll ans = INF;
	for(int i = 1;i <= n;i++)
	    ans = min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const ll INF = 1e18;
const int MAXN = 505;

int n;
ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];

ll getVal1(int a,int b,int c,int d){
	return sum1[b][d] - (c == 0 ? 0 : sum1[b][c - 1]) - (a == 0 ? 0 : sum1[a - 1][d]) + (a == 0 || c == 0 ? 0 : sum1[a - 1][c - 1]);
}

ll getVal2(int a,int b,int c,int d){
	return sum2[b][d] - (c == 0 ? 0 : sum2[b][c - 1]) - (a == 0 ? 0 : sum2[a - 1][d]) + (a == 0 || c == 0 ? 0 : sum2[a - 1][c - 1]);
}

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			if(i != j)
			    scanf("%d",&w[i][j]);
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++)
		    sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1] + w[i][j];
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++)
		    sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1] + (i < j ? w[i][j] : 0);
	}
	for(int i = 1;i <= n;i++){
		f[i][1] = getVal2(0,i,0,i);
		for(int j = 2;j <= i;j++){
			f[i][j] = INF;
			for(int k = 1;k < j;k++)
				f[i][j] = min(f[i][j],f[j - 1][k] + getVal2(j,i,j,i) + getVal1(j,i,0,k - 1));
		}
	}
	ll ans = INF;
	for(int i = 1;i <= n;i++)
	    ans = min(ans,f[n][i]);
	printf("%lld\n",ans);
	return 0;
}


Compiler output:
a.cc:67:10: error: redefinition of 'const ll INF'
   67 | const ll INF = 1e18;
      |          ^~~
a.cc:11:10: note: 'const ll INF' previously defined here
   11 | const ll INF = 1e18;
      |          ^~~
a.cc:68:11: error: redefinition of 'const int MAXN'
   68 | const int MAXN = 505;
      |           ^~~~
a.cc:12:11: note: 'const int MAXN' previously defined here
   12 | const int MAXN = 505;
      |           ^~~~
a.cc:70:5: error: redefinition of 'int n'
   70 | int n;
      |     ^
a.cc:14:5: note: 'int n' previously declared here
   14 | int n;
      |     ^
a.cc:71:4: error: redefinition of 'll w [505][505]'
   71 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |    ^
a.cc:15:4: note: 'll w [505][505]' previously declared here
   15 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |    ^
a.cc:71:18: error: redefinition of 'll f [505][505]'
   71 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                  ^
a.cc:15:18: note: 'll f [505][505]' previously declared here
   15 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                  ^
a.cc:71:32: error: redefinition of 'll sum1 [505][505]'
   71 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                                ^~~~
a.cc:15:32: note: 'll sum1 [505][505]' previously declared here
   15 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                                ^~~~
a.cc:71:49: error: redefinition of 'll sum2 [505][505]'
   71 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                                                 ^~~~
a.cc:15:49: note: 'll sum2 [505][505]' previously declared here
   15 | ll w[MAXN][MAXN],f[MAXN][MAXN],sum1[MAXN][MAXN],sum2[MAXN][MAXN];
      |                                                 ^~~~
a.cc:73:4: error: redefinition of 'll getVal1(int, int, int, int)'
   73 | ll getVal1(int a,int b,int c,int d){
      |    ^~~~~~~
a.cc:17:4: note: 'll getVal1(int, int, int, int)' previously defined here
   17 | ll getVal1(int a,int b,int c,int d){
      |    ^~~~~~~
a.cc:77:4: error: redefinition of 'll getVal2(int, int, int, int)'
   77 | ll getVal2(int a,int b,int c,int d){
      |    ^~~~~~~
a.cc:21:4: note: 'll getVal2(int, int, int, int)' previously defined here
   21 | ll getVal2(int a,int b,int c,int d){
      |    ^~~~~~~
a.cc:81:5: error: redefinition of 'int main()'
   81 | int main(){
      |     ^~~~
a.cc:25:5: note: 'int main()' previously defined here
   25 | int main(){
      |     ^~~~