Submission #6496868
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
void read(pll& x){ scanf("%lld%lld",&x.first, &x.second); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()
const int maxn = 510;
int n;
int cost[maxn][maxn];
ll dp[maxn][maxn];
ll cp[maxn][maxn];
ll gp[maxn][maxn];
int main()
{
cppio();
cin >> n;
rrep(i, n) rrep(j, n) if(i != j) cin >> cost[i][j];
rrep(i, n) rrep(j, n)
cp[i][j] = cp[i-1][j] + cp[i][j-1] - cp[i-1][j-1] + cost[i][j];
rrep(i, n) {
for(int j=i+1; j<=n; ++j) {
gp[i][j] = gp[i][j-1];
for(int k=i; k<j; ++k) {
gp[i][j] += cost[k][j];
}
}
}
memset(dp, 0x7f, sizeof(dp));
dp[1][1] = 0;
for(int i=2; i<=n; ++i)
dp[1][i] = gp[1][i];
auto rect = [&](int l, int r, int d, int u) -> ll {
if(l>r || d>u) return 0;
return cp[r][u] - cp[l-1][u] - cp[r][d-1] + cp[l-1][d-1];
};
rrep(l, n) {
for(int r=l; r<=n; ++r) {
for(int R=r+1; R<=n; ++R) {
dp[r+1][R] = min(dp[r+1][R],
dp[l][r] + gp[r+1][R] +
rect(r+1, R, 1, l-1));
}
}
}
/*
rrep(i, n) {
for(int j=i; j<=n; ++j) printf("dp[%d][%d] = %lld\n", i, j, dp[i][j]);
}
*/
ll ans = 1ll << 60;
rrep(i, n) ans = min(ans, dp[i][n]);
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Negative Cycle |
| User |
Namnamseo |
| Language |
C++14 (GCC 5.4.1) |
| Score |
1200 |
| Code Size |
1817 Byte |
| Status |
AC |
| Exec Time |
346 ms |
| Memory |
7296 KiB |
Compile Error
./Main.cpp: In function ‘void read(int&)’:
./Main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
^
./Main.cpp: In function ‘void read(ll&)’:
./Main.cpp:7:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(ll& x){ scanf("%lld",&x); }
^
./Main.cpp: In function ‘void read(pp&)’:
./Main.cpp:8:52: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(pp& x){ scanf("%d%d",&x.first, &x.second); }
^
./Main.cpp: In function ‘void read(pll&)’:
./Main.cpp:9:57: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
void read(pll& x){...
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
1200 / 1200 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
| All |
01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, sample-01.txt, sample-02.txt, sample-03.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01-01.txt |
AC |
9 ms |
5120 KiB |
| 01-02.txt |
AC |
3 ms |
4736 KiB |
| 01-03.txt |
AC |
183 ms |
6912 KiB |
| 01-04.txt |
AC |
41 ms |
5888 KiB |
| 01-05.txt |
AC |
3 ms |
4608 KiB |
| 01-06.txt |
AC |
4 ms |
4864 KiB |
| 01-07.txt |
AC |
38 ms |
5888 KiB |
| 01-08.txt |
AC |
110 ms |
6528 KiB |
| 01-09.txt |
AC |
18 ms |
5504 KiB |
| 01-10.txt |
AC |
3 ms |
4608 KiB |
| 01-11.txt |
AC |
83 ms |
6272 KiB |
| 01-12.txt |
AC |
22 ms |
5632 KiB |
| 01-13.txt |
AC |
164 ms |
6784 KiB |
| 01-14.txt |
AC |
56 ms |
6016 KiB |
| 01-15.txt |
AC |
3 ms |
4736 KiB |
| 01-16.txt |
AC |
193 ms |
7040 KiB |
| 01-17.txt |
AC |
2 ms |
4480 KiB |
| 01-18.txt |
AC |
10 ms |
5248 KiB |
| 01-19.txt |
AC |
6 ms |
4992 KiB |
| 01-20.txt |
AC |
117 ms |
6528 KiB |
| 01-21.txt |
AC |
254 ms |
7296 KiB |
| 01-22.txt |
AC |
135 ms |
6656 KiB |
| 01-23.txt |
AC |
118 ms |
6528 KiB |
| 01-24.txt |
AC |
53 ms |
6016 KiB |
| 01-25.txt |
AC |
276 ms |
7296 KiB |
| 01-26.txt |
AC |
274 ms |
7296 KiB |
| 01-27.txt |
AC |
274 ms |
7296 KiB |
| 01-28.txt |
AC |
268 ms |
7296 KiB |
| 01-29.txt |
AC |
271 ms |
7296 KiB |
| 01-30.txt |
AC |
276 ms |
7296 KiB |
| 01-31.txt |
AC |
274 ms |
7296 KiB |
| 01-32.txt |
AC |
274 ms |
7296 KiB |
| 01-33.txt |
AC |
268 ms |
7296 KiB |
| 01-34.txt |
AC |
271 ms |
7296 KiB |
| 01-35.txt |
AC |
272 ms |
7296 KiB |
| 01-36.txt |
AC |
272 ms |
7296 KiB |
| 01-37.txt |
AC |
281 ms |
7296 KiB |
| 01-38.txt |
AC |
272 ms |
7296 KiB |
| 01-39.txt |
AC |
272 ms |
7296 KiB |
| 01-40.txt |
AC |
268 ms |
7296 KiB |
| 01-41.txt |
AC |
270 ms |
7296 KiB |
| 01-42.txt |
AC |
275 ms |
7296 KiB |
| 01-43.txt |
AC |
273 ms |
7296 KiB |
| 01-44.txt |
AC |
346 ms |
7296 KiB |
| 01-45.txt |
AC |
268 ms |
7296 KiB |
| 01-46.txt |
AC |
270 ms |
7296 KiB |
| 01-47.txt |
AC |
271 ms |
7296 KiB |
| 01-48.txt |
AC |
271 ms |
7296 KiB |
| sample-01.txt |
AC |
2 ms |
4352 KiB |
| sample-02.txt |
AC |
2 ms |
4352 KiB |
| sample-03.txt |
AC |
2 ms |
4352 KiB |