Submission #58970


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7;
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;
signed main(void){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<vector<lol> > m(1005, vector<lol>(1005, 0));
//最大正方形
int maxv = 0,l;
vector<vit> dp(1005, vit(1005, 0));
reps(i, h){
reps(j, w){
cin >> l;
if(l == 0){
dp[i][j] = min({dp[i - 1][j - 1], dp[i][j - 1], dp[i - 1][j]}) + 1;
maxv = max(maxv, dp[i][j]);
}
}
}
reps(i, h){
reps(j, w){
cin >> m[i][j];
}
}
/*
//二次元累積和作成
reps(i,h){
reps(j,w){
m[i][j] += m[i][j-1];
}
}
reps(i,h){
reps(j,w){
m[j][i] += m[j-1][i];
}
}*/
lol nasu = LINF, ans;
reps(i, h){
reps(j, w){
if(maxv == dp[i][j]){
ans = 0;
rep(na, maxv){
rep(su, maxv){
ans += m[i - na][j - su];
}
}
nasu = min(nasu, ans);
}
}
}
if(maxv == 0){
cout << "-1\n";
} else {
cout << nasu << '\n';
}
return 0;
}

ステータス

項目 データ
問題 1283 - Agriculture
ユーザー名 NASSUN_ei1906
投稿日時 2020-04-12 14:53:20
言語 C++14
状態 Accepted
得点 300
ソースコード長 1689 Byte
最大実行時間 113 ms
最大メモリ使用量 12620 KB

セット

セット 得点 Cases
1 ALL 300 / 300 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 37 ms 12508 KB
1
in02.txt AC 70 ms 12316 KB
1
in03.txt AC 33 ms 12388 KB
1
in04.txt AC 34 ms 12328 KB
1
in05.txt AC 40 ms 12404 KB
1
in06.txt AC 57 ms 12348 KB
1
in07.txt AC 40 ms 12420 KB
1
in08.txt AC 45 ms 12360 KB
1
in09.txt AC 92 ms 12436 KB
1
in10.txt AC 30 ms 12508 KB
1
in11.txt AC 107 ms 12456 KB
1
in12.txt AC 25 ms 12404 KB
1
in13.txt AC 66 ms 12472 KB
1
in14.txt AC 61 ms 12412 KB
1
in15.txt AC 27 ms 12360 KB
1
in16.txt AC 88 ms 12432 KB
1
in17.txt AC 67 ms 12504 KB
1
in18.txt AC 64 ms 12448 KB
1
in19.txt AC 83 ms 12516 KB
1
in20.txt AC 31 ms 12460 KB
1
in21.txt AC 47 ms 12532 KB
1
in22.txt AC 30 ms 12472 KB
1
in23.txt AC 27 ms 12416 KB
1
in24.txt AC 61 ms 12484 KB
1
in25.txt AC 50 ms 12420 KB
1
in26.txt AC 39 ms 12492 KB
1
in27.txt AC 38 ms 12568 KB
1
in28.txt AC 41 ms 12512 KB
1
in29.txt AC 41 ms 12460 KB
1
in30.txt AC 41 ms 12404 KB
1
in31.txt AC 25 ms 12472 KB
1
in32.txt AC 111 ms 12548 KB
1
in33.txt AC 24 ms 12620 KB
1
in34.txt AC 22 ms 12572 KB
1
in35.txt AC 107 ms 12520 KB
1
in36.txt AC 26 ms 12592 KB
1
in37.txt AC 113 ms 12544 KB
1
in38.txt AC 112 ms 12484 KB
1
sample01.txt AC 27 ms 12432 KB
1
sample02.txt AC 24 ms 12508 KB
1
sample03.txt AC 34 ms 12584 KB
1