| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 715411 | Toxtaq | Raisins (IOI09_raisins) | C++17 | 585 ms | 26836 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int>>chocolate, pref;
int table[51][51][51][51];
int rec(int x1, int y1, int x2, int y2){
int cnt = pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
int res = 1e9;
if(x1 == x2 && y1 == y2)return 0;
if(table[x1][y1][x2][y2] != -1)return table[x1][y1][x2][y2];
if(x1 != x2){
for(int i = x1;i < x2;++i){
res = min(res, rec(x1, y1, i, y2) + rec(i + 1, y1, x2, y2) + cnt);
}
}
if(y1 != y2){
for(int i = y1;i < y2;++i){
res = min(res, rec(x1, y1, x2, i) + rec(x1, i + 1, x2, y2) + cnt);
}
}
return table[x1][y1][x2][y2] = res;
}
int main()
{
cin >> n >> m;
chocolate.assign(n + 1, vector<int>(m + 1));
pref.assign(n + 1, vector<int>(m + 1));
for(int i = 1;i <= n;++i){
for(int j = 1;j <= m;++j){
cin >> chocolate[i][j];
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + chocolate[i][j];
}
}
for(int i = 0;i < 51;++i){
for(int j = 0;j < 51;++j){
for(int k = 0;k < 51;++k){
for(int l = 0;l < 51;++l){
table[i][j][k][l] = -1;
}
}
}
}
cout << rec(1, 1, n, m);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
