比赛 20161115 评测结果 WWAWAWAAAA
题目名称 军队 最终得分 60
用户昵称 1azyReaper 运行时间 0.177 s
代码语言 C++ 内存使用 15.57 MiB
提交时间 2016-11-15 10:51:36
显示代码纯文本
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <cstdio>
  5. #include <algorithm>
  6. #include <cmath>
  7. #define ll long long
  8. #define max 1000001
  9. using namespace std;
  10. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  11. ll n,k,p[max],c[max];
  12. inline ll read()
  13. {
  14. char tmp=getchar();
  15. ll ans=0,f=1;
  16. while(tmp<'0'||tmp>'9')
  17. {
  18. if(tmp=='-')
  19. f=-f;
  20. tmp=getchar();
  21. }
  22. while(tmp>='0'&&tmp<='9')
  23. {
  24. ans=ans*10-'0'+tmp;
  25. tmp=getchar();
  26. }
  27. return ans*f;
  28. }
  29. inline ll gcd(ll x,ll y)
  30. {
  31. if(y==0)
  32. return x;
  33. else
  34. return gcd(y,x%y);
  35. }
  36. ll work()
  37. {
  38. ll ans=0,ft=1;
  39. for(int i=1;i<=n;i++)
  40. {
  41. for(int j=i-1;j>=ft;j--)
  42. {
  43. if(gcd(p[j],p[i])>1)
  44. {
  45. ft=j+1;
  46. break;
  47. }
  48. if(c[i]-c[ft-1]>=k&&i-ft+1>=ans)
  49. {
  50. ans=i-ft;
  51. }
  52. }
  53. }
  54. printf("%lld\n",ans);
  55. }
  56. int main(int argc, char** argv)
  57. {
  58. freopen("tarmy.in","r",stdin);
  59. freopen("tarmy.out","w",stdout);
  60. n=read();
  61. k=read();
  62. for(ll i=1;i<=n;i++)
  63. {
  64. p[i]=read();
  65. c[i]=c[i-1]+p[i];
  66. }
  67. work();
  68. return 0;
  69. }