답안 #798068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798068 2023-07-30T10:40:57 Z aymanrs 건포도 (IOI09_raisins) C++14
100 / 100
253 ms 24768 KB
    #include<bits/stdc++.h>
    #pragma GCC optimize("Ofast,unroll-loops")
    #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
    const int MOD = 1e9+7;
    using namespace std;
    void solve(){
    	int n, m;
    	cin >> n >> m;
    	int dp[n][m][n][m];
    	int pr[n][m];
    	for(int i = 0;i < n;i++) for(int j = 0;j < m;j++) {
    		cin >> pr[i][j];
    		dp[0][0][i][j] = 0;
    		if(i) pr[i][j] += pr[i-1][j];
    		if(j) {
    			pr[i][j] += pr[i][j-1];
    			if(i) pr[i][j] -= pr[i-1][j-1];
    		}
    	}
    	for(int h = 0;h < n;h++){
    		for(int w = h ? 0 : 1;w < m;w++){
              #pragma GCC ivdep
    			for(int i = 0;i+h < n;i++){
                  #pragma GCC ivdep
    				for(int j = 0;j+w < m;j++){
    					dp[h][w][i][j] = pr[i+h][j+w]-(i ? pr[i-1][j+w] : 0)-(j ? pr[i+h][j-1] : 0)+(i&&j ? pr[i-1][j-1] : 0);
    					int x = INT_MAX;
    					for(int k = 0;k < h;k++) x = min(x, dp[k][w][i][j]+dp[h-k-1][w][i+k+1][j]);
    					for(int k = 0;k < w;k++) x = min(x, dp[h][k][i][j]+dp[h][w-k-1][i][j+k+1]);
    					dp[h][w][i][j] += x;
    				}
    			}
    		}
    	}
    	cout << dp[n-1][m-1][0][0] << '\n';
    }
    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	solve();
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 6 ms 1364 KB Output is correct
10 Correct 9 ms 1844 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 26 ms 4176 KB Output is correct
13 Correct 42 ms 6100 KB Output is correct
14 Correct 12 ms 2312 KB Output is correct
15 Correct 51 ms 7252 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 20 ms 3364 KB Output is correct
18 Correct 129 ms 14932 KB Output is correct
19 Correct 212 ms 21972 KB Output is correct
20 Correct 253 ms 24768 KB Output is correct