Submission #9673129
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }
template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os<<"("<<p.first<<","<<p.second<<")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os<<"{";
rep(i, v.size()) {
if (i) os<<",";
os<<v[i];
}
os<<"}";
return os;
}
int a[2010][2010];
int main() {
int H, W;
int N, M;
cin >> H >> W >> N >> M;
V<string> s(N);
rep(i, N) cin >> s[i];
V<int> xs, ys;
rep(i, N) {
xs.pb(i);
xs.pb(H-N+i+1);
}
rep(i, M) {
ys.pb(i);
ys.pb(W-M+i+1);
}
sort(ALL(xs));
sort(ALL(ys));
rep(i, N) {
rep(j, M) if (s[i][j] == '#') {
int p = lower_bound(ALL(xs), i) - xs.begin();
int q = lower_bound(ALL(ys), j) - ys.begin();
int r = lower_bound(ALL(xs), H-N+i+1) - xs.begin();
int s = lower_bound(ALL(ys), W-M+j+1) - ys.begin();
++a[r][s]; ++a[p][q]; --a[p][s]; --a[r][q];
}
}
ll ans = 0;
int sx = xs.size(), sy = ys.size();
rep(i, sx) {
rep(j, sy - 1) {
a[i][j+1] += a[i][j];
}
}
rep(i, sx-1) {
rep(j, sy) {
a[i+1][j] += a[i][j];
}
}
rep(i, sx-1) {
rep(j, sy-1) {
if (a[i][j]>0) {
ans += (ll)(xs[i+1] - xs[i]) * (ys[j+1] - ys[j]);
}
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - ハンコ |
User |
satashun |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
2034 Byte |
Status |
AC |
Exec Time |
70 ms |
Memory |
17024 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
49 ms |
8832 KB |
02.txt |
AC |
7 ms |
7936 KB |
03.txt |
AC |
6 ms |
9728 KB |
04.txt |
AC |
44 ms |
16512 KB |
05.txt |
AC |
3 ms |
3456 KB |
06.txt |
AC |
42 ms |
15488 KB |
07.txt |
AC |
3 ms |
1152 KB |
08.txt |
AC |
6 ms |
13696 KB |
09.txt |
AC |
2 ms |
384 KB |
10.txt |
AC |
40 ms |
12544 KB |
11.txt |
AC |
3 ms |
3456 KB |
12.txt |
AC |
6 ms |
4352 KB |
13.txt |
AC |
70 ms |
13312 KB |
14.txt |
AC |
1 ms |
256 KB |
15.txt |
AC |
5 ms |
13568 KB |
16.txt |
AC |
39 ms |
8960 KB |
17.txt |
AC |
7 ms |
5888 KB |
18.txt |
AC |
6 ms |
9728 KB |
19.txt |
AC |
4 ms |
1664 KB |
20.txt |
AC |
27 ms |
11136 KB |
21.txt |
AC |
3 ms |
1024 KB |
22.txt |
AC |
9 ms |
4608 KB |
23.txt |
AC |
49 ms |
17024 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |
sample-03.txt |
AC |
1 ms |
256 KB |
sample-04.txt |
AC |
1 ms |
256 KB |
sample-05.txt |
AC |
1 ms |
256 KB |