답안 #316528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316528 2020-10-26T14:15:48 Z ronnith Strah (COCI18_strah) C++14
0 / 110
1000 ms 41080 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define bin1(a) __builtin_popcount(a)
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define de cerr
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)/(__gcd(a,b))) * b)
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define v vector
#define p pair
#define pii p<int,int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
using namespace __gnu_pbds;
ll modF=1e9+7;

/*OUTPUT

*/

int nax = 2001;
int n,m;
v<v<ll>> pre(nax,v<ll>(nax,0));
v<v<char>> a(nax,v<char>(nax));

void build(){
	for(int i = 1;i <= n;i ++){
		for(int j = 1;j <= m;j ++){
			if(a[i][j] == '#'){
				pre[i][j] ++;
			}
			pre[i][j] += pre[i][j - 1];
		}
	}
	for(int j = 1;j <= m;j ++){
		for(int i = 1;i <= n;i ++){
			pre[i][j] += pre[i - 1][j];
		}
	}
}

ll sum(ll a,ll b,ll c,ll d){
	ll res = pre[c][d] - pre[c][b - 1] - pre[a - 1][d] + pre[a - 1][b - 1];
	return res;
}

void solve(){
	cin >> n >> m;
	v<v<pii>> h(n + 1);
	rep(i,1,n + 1){
		int lst = -1;
		bool fl = true;
		rep(j,1,m + 1){
			cin >> a[i][j];
			if(a[i][j] == '.'){
				if(fl){
					lst = j;
					fl = false;
				}
			}
			else{
				if(!fl){
					h[i].pb(mk(lst,j - 1));
					fl = true; 
				}
			}
		}
		if(!fl){
			h[i].pb(mk(lst,m));
		}
	}
	build();
	ll ans = 0;
	for(ll i = 1;i <= n;i ++){
		for(auto e:h[i]){
			ll r = e.s;
			ll l = e.f;
			vi pr1(r - l + 2);
			vi pr2(r - l + 2);
			for(int i = 1;i < r - l + 2;i ++){
				pr1[i] = i;
				pr1[i] += pr1[i - 1];
			}
			for(int i = 1;i < r - l + 2;i ++){
				pr2[i] = (r - l + 2 - i)* i;
				pr2[i] += pr2[i - 1];
			}
			for(ll k = i;k <= n;k ++){
				while(r > l and sum(i,r,k,r) != 0){
					r --;
				}
				while(l < r and sum(i,l,k,l) != 0){
					l ++;
				}
				if(sum(i,l,k,r) == 0){
					// debug2(i,l);
					// debug2(k,r);
					// de << ln;
					// ans += (k - i + 1) * (r - l + 1) + ((r - l + 1) * (r - l) * (k - i + 1)) / 2;

					ans += (k - i + 1) * (pr2[r - l + 1] - (e.s - e.f + 1 - (r - l + 1)) * pr1[r - l + 1]);

				}
			}
		}
	}
	cout << ans << ln;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	// cin >> t;
	while(t --){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 35704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 35712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 35968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 35920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 35712 KB Output is correct
2 Incorrect 33 ms 35840 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 706 ms 37500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 41080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 282 ms 36000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 392 ms 36224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 475 ms 35968 KB Output isn't correct
2 Halted 0 ms 0 KB -