Submission #2944537


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int N,M;
char A[2000][2000];
ll a[2000][2000];
ll cul(){
	ll ans=0;
	FOR(i,0,N){
		ROF(j,0,M){
			if(A[i][j]=='.'){
				int cnt=1;
				while(j>=0&&A[i][j]=='.'){
					a[i][j]=cnt;
					j--;
					cnt++;
				}
				j++;
			}else{
				a[i][j]=0;
			}
		}
	}
	FOR(i,1,N){
		FOR(j,0,M-1){
			if(A[i][j]=='.'){
				int mx=i;
				mx--;
				while(mx>=0&&A[mx][j]=='.'){
					ans+=a[mx][j+1];
					mx--;
				}
			}
		}
	}
	return ans;
}
ll cul2(){
	FOR(i,0,N){
		FOR(j,0,M){
			a[i][j]=0;
		}
	}
	ll ans=0;
	FOR(j,0,M){
		ROF(i,0,N){
			if(A[i][j]=='.'){
				int cnt=1;
				while(i>=0&&A[i][j]=='.'){
					a[i][j]=cnt;
					i--;
					cnt++;
				}
				i++;
			}else{
				a[i][j]=0;
			}
		}
	}
	FOR(i,0,N-1){
		FOR(j,0,M-1){
			if(A[i][j]=='.'){
				int my=j;
				my++;
				while(my<M&&A[i][my]=='.'){
					ans+=a[i+1][my];
					my++;
				}
			}
		}
	}
	return ans;
}
ll cul3(){
	FOR(i,0,N){
		FOR(j,0,M){
			a[i][j]=0;
		}
	}
	ll ans=0;
	FOR(i,0,N){
		FOR(j,0,M){
			if(A[i][j]=='.'){
				int cnt=1;
				while(j<M&&A[i][j]=='.'){
					a[i][j]=cnt;
					j++;
					cnt++;
				}
				j--;
			}else{
				a[i][j]=0;
			}
		}
	}
	FOR(i,0,N-1){
		ROF(j,1,M){
			if(A[i][j]=='.'){
				int mx=i;
				mx++;
				while(mx<N&&A[mx][j]=='.'){
					ans+=a[mx][j-1];
					mx++;
				}
			}
		}
	}
	return ans;
}
ll cul4(){
	FOR(i,0,N){
		FOR(j,0,M){
			a[i][j]=0;
		}
	}
	ll ans=0;
	FOR(j,0,M){
		FOR(i,0,N){
			if(A[i][j]=='.'){
				int cnt=1;
				while(i<N&&A[i][j]=='.'){
					a[i][j]=cnt;
					i++;
					cnt++;
				}
				i--;
			}else{
				a[i][j]=0;
			}
		}
	}
	ROF(j,1,M){
		ROF(i,1,N){
			if(A[i][j]=='.'){
				int my=j;
				my--;
				while(my>=0&&A[i][my]=='.'){
					ans+=a[i-1][my];
					my--;
				}
			}
		}
	}
	return ans;
}
int main(){
	cin>>N>>M;
	FOR(i,0,N){
		FOR(j,0,M){
			cin>>A[i][j];
		}
	}
    ll  aa=cul()+cul2()+cul3()+cul4();
	cout<<aa<<endl;
	return 0;
}

Submission Info

Submission Time
Task C - 右折
User nii
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2559 Byte
Status
Exec Time 2107 ms
Memory 35456 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 0 / 400 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, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 473 ms 35456 KB
02.txt 472 ms 35456 KB
03.txt 471 ms 35456 KB
04.txt 471 ms 35456 KB
05.txt 640 ms 35456 KB
06.txt 645 ms 35456 KB
07.txt 645 ms 35456 KB
08.txt 636 ms 35456 KB
09.txt 2107 ms 35328 KB
10.txt 2103 ms 35328 KB
11.txt 2103 ms 35328 KB
12.txt 2104 ms 35328 KB
13.txt 323 ms 35456 KB
14.txt 314 ms 35456 KB
15.txt 2104 ms 35328 KB
16.txt 2103 ms 35328 KB
17.txt 288 ms 35456 KB
18.txt 298 ms 35456 KB
19.txt 294 ms 35456 KB
20.txt 295 ms 35456 KB
21.txt 767 ms 35456 KB
22.txt 756 ms 35456 KB
23.txt 770 ms 35456 KB
24.txt 771 ms 35456 KB
25.txt 1556 ms 35456 KB
26.txt 1603 ms 35456 KB
27.txt 1595 ms 35456 KB
28.txt 1558 ms 35456 KB
29.txt 2 ms 2304 KB
30.txt 2 ms 2304 KB
31.txt 2 ms 2304 KB
32.txt 2 ms 2304 KB
33.txt 2 ms 2304 KB
34.txt 2 ms 2304 KB
35.txt 2 ms 2304 KB
36.txt 2 ms 2304 KB
s1.txt 2 ms 2304 KB
s2.txt 2 ms 2304 KB
s3.txt 2 ms 2304 KB