比赛 20161115 评测结果 WWWWWWWWWW
题目名称 军队 最终得分 0
用户昵称 ss 运行时间 0.346 s
代码语言 C++ 内存使用 187.26 MiB
提交时间 2016-11-15 11:20:12
显示代码纯文本
  1. #include<cstdio>
  2. #include<iostream>
  3. #include<iomanip>
  4. using namespace std;
  5. const int maxn=1000000+10;
  6. signed int k, total;
  7. int n, ans;
  8. int st, en;
  9. int s[maxn], tt[maxn];
  10. int check(int ,int );
  11. int pd(int ,int );
  12. int main()
  13. {
  14. freopen("tarmy.in", "r", stdin);
  15. freopen("tarmy.out", "w", stdout);
  16. int i, j;
  17. scanf("%d%d", &n, &k);
  18. signed int sp=0;
  19. for(i=1; i<=n; i++)
  20. {
  21. cin>>s[i];
  22. sp+=s[i];
  23. if(i>=2)
  24. {
  25. if(pd(s[i],s[i-1]))
  26. tt[i-1]=1;
  27. else tt[i-1]=0;
  28. }
  29. }
  30. if(sp<=k)
  31. {
  32. if(sp<k)
  33. {
  34. cout<<"0"<<endl;
  35. return 0;
  36. }
  37. if(sp==k)
  38. {
  39. cout<<n<<endl;
  40. return 0;
  41. }
  42. }
  43. int qq=0, pp=0;
  44. for(i=1; i<=n-1; i++)
  45. {
  46. if(tt[i]==0)
  47. {
  48. pp++;
  49. qq=max(qq,pp);
  50. }
  51. if(tt[i]==1)
  52. {
  53. pp=0;
  54. }
  55. }
  56. pp=0;
  57. for(i=1; i<=n-1; i++)
  58. {
  59. if(tt[i]==0)
  60. {
  61. pp++;
  62. }
  63. if(pp==qq)
  64. {
  65. en=i+1;
  66. break;
  67. }
  68. if(tt[i]==1) pp=0;
  69. }
  70. st=en-qq;
  71. // cout<<st<<en<<endl;
  72. for(i=st; i<=en; i++) total+=s[i];
  73. check(st, en);
  74. ans=en-st+1;
  75. // cout<<ans<<endl;
  76. if(total>=k)
  77. cout<<ans<<endl;
  78. else
  79. cout<<"0"<<endl;
  80. return 0;
  81. }
  82. int check(int x, int y)
  83. {
  84. int i, j;
  85. for(i=x; i<=y; i++)
  86. {
  87. if(x!=st||y!=en) break;
  88. for(j=1; j+i<=y; j++)
  89. {
  90. if(!pd(s[i],s[i+j]))
  91. {
  92. if(s[i]>s[i+j])
  93. {
  94. total-=s[i+j];
  95. en=i+j;
  96. }
  97. else
  98. {
  99. total-=s[i];
  100. st=i+1;
  101. }
  102. break;
  103. }
  104. }
  105. }
  106. }
  107. int pd(int x, int y)
  108. {
  109. if(x>y)
  110. {
  111. if(x%y==0)
  112. return 1;
  113. else return 0;
  114. }
  115. if(x<y)
  116. {
  117. if(y%x==0)
  118. return 1;
  119. else return 0;
  120. }
  121. return 1;
  122. }