Spotlights
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.

You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the four directions (if you look at the stage from above) — left, right, up or down. Thus, the spotlight's position is a cell it is placed to and a direction it shines.

A position is good if two conditions hold:

  • there is no actor in the cell the spotlight is placed to;
  • there is at least one actor in the direction the spotlight projects.

Count the number of good positions for placing the spotlight. Two positions of spotlight are considered to be different if the location cells or projection direction differ.

Input

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the plan.

The next n lines contain m integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell will remain empty. It is guaranteed that there is at least one actor in the plan.

Output

Print one integer — the number of good positions for placing the spotlight.

Examples
input
2 4
0 1 0 0
1 0 1 0
output
9
input
4 4
0 0 0 0
1 0 0 1
0 1 1 0
0 1 0 0
output
20
Note

In the first example the following positions are good:

  1. the (1, 1) cell and right direction;
  2. the (1, 1) cell and down direction;
  3. the (1, 3) cell and left direction;
  4. the (1, 3) cell and down direction;
  5. the (1, 4) cell and left direction;
  6. the (2, 2) cell and left direction;
  7. the (2, 2) cell and up direction;
  8. the (2, 2) and right direction;
  9. the (2, 4) cell and left direction.

Therefore, there are 9 good positions in this example.

分析:预处理前缀和,模拟;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
#define intxt freopen("in.txt","r",stdin)
const int maxn=1e3+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,t,a[maxn][maxn],b[maxn][maxn];
ll ans;
int main()
{
int i,j;
scanf("%d%d",&n,&m);
rep(i,,n)rep(j,,m)scanf("%d",&a[i][j]);
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(i,,n)
{
rep(j,,m)
{
b[i][j]+=b[i][j-];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(i,,n)
{
for(j=m;j>=;j--)
{
b[i][j]+=b[i][j+];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(j,,m)
{
for(i=n;i>=;i--)
{
b[i][j]+=b[i+][j];
if(b[i][j]&&!a[i][j])ans++;
}
}
rep(i,,n)rep(j,,m)b[i][j]=a[i][j];
rep(j,,m)
{
rep(i,,n)
{
b[i][j]+=b[i-][j];
if(b[i][j]&&!a[i][j])ans++;
}
}
printf("%lld\n",ans);
//system("Pause");
return ;
}

Spotlights的更多相关文章

  1. Codeforces #380 div2 B(729B) Spotlights

    B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. 【Codeforces 738B】Spotlights

    Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which act ...

  3. [CF738B]Spotlights(前缀和,模拟)

    题目链接:http://codeforces.com/contest/738/problem/B 题意:问多少个0的方向,使得方向上至少有一个1. 四个方向统计一遍前缀和,向上向左正着记,向下向右倒着 ...

  4. Codeforces Round #380 (Div. 2)/729B Spotlights 水题

    Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which act ...

  5. 【47.76%】【Round #380B】Spotlights

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. Spotlights【思维+前缀和优化】

    https://blog.csdn.net/mengxiang000000/article/details/53291883   原博客地址 http://codeforces.com/group/1 ...

  7. Unity 5 中的全局光照技术详解

    貌似是某位好人翻译的 https://unity3d.com/cn/learn/tutorials/topics/graphics/unity-5-lighting-and-rendering#rd? ...

  8. Codeforces Round #380 (Div. 2) 总结分享

    B. Spotlights 题意 有n×m个格子的矩形舞台,每个格子里面可以安排一个演员或聚光灯,聚光灯仅可照射一个方向(俯视,上下左右).若聚光灯能照到演员,则称为"good positi ...

  9. Unity 用户手册用户指南二维纹理 (Texture 2D)

    http://www.58player.com/blog-2327-953.html 二维纹理 (Texture 2D) 纹理 (Textures) 使您的 网格 (Meshes).粒子 (Parti ...

随机推荐

  1. ssh原理[转]

    SSH是每一台Linux电脑的标准配置. 随着Linux设备从电脑逐渐扩展到手机.外设和家用电器,SSH的使用范围也越来越广.不仅程序员离不开它,很多普通用户也每天使用. SSH具备多种功能,可以用于 ...

  2. 导入excel表格的数据--->到mysql中

    01下载excel类,将Classes文件夹放入ThinkPHP\Extend\Vendor\位置 下载地址 http://phpexcel.codeplex.com/releases/view/26 ...

  3. Servlet图片上传

    package com.servlet; import java.io.DataInputStream; import java.io.FileOutputStream; import java.io ...

  4. Qt_DX

    #ifndef MY_FRAME__HH__ #define MY_FRAME__HH__ #include <QtGui/QWidget> struct IDirect3D9; stru ...

  5. Dubbo协议与连接控制

    协议参考手册 (+) (#) 推荐使用Dubbo协议 性能测试报告各协议的性能情况,请参见:性能测试报告 (+) dubbo:// (+) (#) Dubbo缺省协议采用单一长连接和NIO异步通讯,适 ...

  6. poj2140(奇因数的个数)

    #include<stdio.h>int main(){ int n,s=0; scanf("%d",&n); for(int i=1;i<=n;i++) ...

  7. java读写串口

    http://blog.csdn.net/xxyy888/article/details/8946046

  8. uilabel 复制

    //添加一个长按响应方法 - (void)addLongPressGestureRecognizer { UILongPressGestureRecognizer * longPress = [[UI ...

  9. 将数组写入plist文件

    data 加载plist [NSBundle mainBundle] [arr writeToURL:<#(NSURL *)#> atomically:<#(BOOL)#>]

  10. cookie和session的区别(搜狐笔试考到的一个题目)

    一.cookie机制和session机制的区别***************************************************************************** ...