[USACO16JAN]子共七Subsequences Summing to Sevens
a[i]表示前缀和
如果a[i]%7==t&&a[j]%7==t
那么a[j]-a[i-1]一定是7的整数倍,
这样就o(n)扫一遍,不断更新答案就可以了。

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#define inf 2147483647
#define For(i,a,b) for(register long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar()
//by war
//2017.10.12
using namespace std;
long long n;
long long a[];
long long p[];
long long x,l,ans;
void in(long long &x)
{
char c=g();x=;
while(c<''||c>'')c=g();
while(c<=''&&c>='')x=x*+c-'',c=g();
}
void o(long long x)
{
if(x>)o(x/);
p(x%+'');
}
int main()
{
in(n);
For(i,,n)
{
in(x);
a[i]=x+a[i-];
}
/* for(register long long len=n;len>=1;len--)
{
For(i,1,n-len+1)
if((a[i+len-1]-a[i-1])%7==0)
{
o(len);
exit(0);
}
}*/
For(i,,)
p[i]=inf;
For(i,,n)
{
p[a[i]%]=min(p[a[i]%],i);
ans=max(ans,i-p[a[i]%]);
}
o(ans);
return ;
}

最新文章

  1. 【UOJ #13】【UER #1】跳蚤OS
  2. editplus如何配置php编译环境?
  3. ProgressDialog的使用
  4. Python语言精要---下
  5. VC高手们的博客
  6. php开发学习目录
  7. 删除WIN7系统的共享文件
  8. MFC永久窗口对象与临时窗口对象
  9. Python ---------copy
  10. 【Alpha】阶段总结报告
  11. Unsupported&#160;major.minor&#160;version&#160;52.0
  12. 设计模式のObserver Pattern(观察者模式)----行为模式
  13. thinkphp 在本地正常,在云端ubuntu下报控制器不存在
  14. 九、使用多线程——NSThread,GCD和NSOperation
  15. WinForm版图像编辑小程序(实现图像拖动、缩放、旋转、抠图)
  16. [ci]jenkins-slave的添加(vm模式,通过ssh和jnlp)
  17. HBase的Shell命令和JavaAPI
  18. getHibernateTemplate()的用法 (转)
  19. C#使用Gzip解压缩完整读取网页内容
  20. Objective-C系列总结之基础知识

热门文章

  1. Problem A: 选举 解题报告
  2. 【COGS1752】 BOI2007—摩基亚Mokia
  3. bzoj2616: SPOJ PERIODNI——笛卡尔树+DP
  4. win32 ini
  5. LSTM介绍
  6. docker 原理
  7. log4j2常见配置
  8. freemark+ITextRenderer 生成PDF,设置pdf的页面大小
  9. python---django中orm的使用(1)
  10. 在angularJs实现批量删除