Submission #165793

# Submission time Handle Problem Language Result Execution time Memory
165793 2019-11-28T20:13:20 Z muhi1112 Strah (COCI18_strah) C++17
0 / 110
674 ms 8312 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=2e3+5;

int n,m,hist[N],seg[4*N];
char grid[N][N];

ll dpf(ll i,ll j){
	//cout<<"i = "<<i<<" j = "<<j<<endl;
	return ((i+1)*(j+1)*i*j)/4;
}
void build(int v,int tl,int tr){
	if(tl == tr){
		seg[v] = tl;
	}
	else{
		int tm = (tl+tr)/2;
		build(v*2,tl,tm);
		build(v*2+1,tm+1,tr);
		seg[v]=(hist[seg[v*2]] < hist[seg[v*2+1]] ? seg[v*2] : seg[v*2+1]);
	}
}

ll query(int v,int tl,int tr,int l,int r){
	if(l > r)return -1;
	if(l==tl && r==tr)return seg[v];
    else{
    	int tm = (tl+tr)/2;
    	ll left = query(v*2,tl,tm,l,min(r,tm));
    	ll right = query(v*2+1,tm+1,tr,max(l,tm+1),r);
    	if(left == -1)return right;
    	if(right == -1)return left;
    	return hist[left] < hist[right] ? left : right;
    }

}

ll solve1(int i,int j){
	if(i==j)return dpf(1,hist[query(1,1,m,i,j)]);
	if(i>j)return 0;
	int k=query(1,1,m,i,j);
	//cout<<i<<" "<<j<<" "<<k<<endl;
	ll ans=dpf(hist[k],j-i+1);
	return ans+=solve1(i,k)+solve1(k+2,j);
}
ll solve(){
	ll ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(grid[i][j]=='#'){
				hist[j]=0;
			}
			else hist[j]++;
		}
		memset(seg,-1,sizeof(seg));
		build(1,0,m-1);
		ans+=solve1(1,m);
		//cout<<ans<<endl;
	}
	return ans;
}
int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>grid[i][j];
		}
	}
	cout<<solve()<<endl;

return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1144 KB Output is correct
2 Incorrect 15 ms 1016 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 3116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 414 ms 5472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 283 ms 3576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 4216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 674 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -