Submission #2945045


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[4][2000][2000];
ll cul(){
	FOR(i,0,N){
		ROF(j,0,M){
			if(A[i][j]=='.'){
				int cnt=1;
				while(j>=0&&A[i][j]=='.'){
					a[0][i][j]=cnt;
					j--;
					cnt++;
				}
				j++;
			}else{
				a[0][i][j]=0;
			}
		}
	}
	FOR(j,0,M){
		ROF(i,0,N){
			if(A[i][j]=='.'){
				int cnt=1;
				while(i>=0&&A[i][j]=='.'){
					a[1][i][j]=cnt;
					i--;
					cnt++;
				}
				i++;
			}else{
				a[1][i][j]=0;
			}
		}
	}
	FOR(i,0,N){
		FOR(j,0,M){
			if(A[i][j]=='.'){
				int cnt=1;
				while(j<M&&A[i][j]=='.'){
					a[2][i][j]=cnt;
					j++;
					cnt++;
				}
				j--;
			}else{
				a[2][i][j]=0;
			}
		}
	}
	FOR(j,0,M){
		FOR(i,0,N){
			if(A[i][j]=='.'){
				int cnt=1;
				while(i<N&&A[i][j]=='.'){
					a[3][i][j]=cnt;
					i++;
					cnt++;
				}
				i--;
			}else{
				a[3][i][j]=0;
			}
		}
	}
}
ll culcul(){
	ll ans=0;
	FOR(i,0,N){
		FOR(j,0,M){
			if(A[i][j]=='.'){
				if(j+1<M&&i+1<N){
					ans+=a[0][i][j+1]*a[1][i+1][j];
				}
				if(i+1<N&&j-1>=0){
					ans+=a[1][i+1][j]*a[2][i][j-1];
				}
				if(j-1>=0&&i-1>=0){
					ans+=a[2][i][j-1]*a[3][i-1][j];
				}
				if(i-1>=0&&j+1<M){
					ans+=a[3][i-1][j]*a[0][i][j+1];
				}
			}
		}
	}
	return ans;
}
int main(){
	cin>>N>>M;
	FOR(i,0,N){
		FOR(j,0,M){
			cin>>A[i][j];
		}
	}
	cul();
	cout<<culcul()<<endl;
	return 0;
}

Submission Info

Submission Time
Task C - 右折
User nii
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1960 Byte
Status
Exec Time 469 ms
Memory 129152 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 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 468 ms 129152 KB
02.txt 466 ms 129152 KB
03.txt 469 ms 129152 KB
04.txt 466 ms 129152 KB
05.txt 426 ms 129152 KB
06.txt 435 ms 129152 KB
07.txt 426 ms 129152 KB
08.txt 427 ms 129152 KB
09.txt 414 ms 129152 KB
10.txt 413 ms 129152 KB
11.txt 414 ms 129152 KB
12.txt 413 ms 129152 KB
13.txt 421 ms 129152 KB
14.txt 418 ms 129152 KB
15.txt 421 ms 129152 KB
16.txt 412 ms 129152 KB
17.txt 403 ms 129152 KB
18.txt 403 ms 129152 KB
19.txt 409 ms 129152 KB
20.txt 409 ms 129152 KB
21.txt 425 ms 129152 KB
22.txt 424 ms 129152 KB
23.txt 425 ms 129152 KB
24.txt 434 ms 129152 KB
25.txt 419 ms 129152 KB
26.txt 418 ms 129152 KB
27.txt 418 ms 129152 KB
28.txt 418 ms 129152 KB
29.txt 3 ms 8448 KB
30.txt 3 ms 8448 KB
31.txt 3 ms 8448 KB
32.txt 3 ms 8448 KB
33.txt 3 ms 8448 KB
34.txt 3 ms 8448 KB
35.txt 3 ms 8448 KB
36.txt 3 ms 8448 KB
s1.txt 3 ms 8448 KB
s2.txt 3 ms 8448 KB
s3.txt 3 ms 8448 KB