Thursday, 27 July 2017

Lightoj 1134 - Be Efficient

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int dp[100005];
  4. int main()
  5. {
  6.     int ts;
  7.     cin>>ts;
  8.     for(int h = 1; h <= ts; h++){
  9.         long long int n, sum= 0, ans = 0, k;
  10.     cin>>n>>k;
  11.     memset(dp, 0sizeof(dp));
  12.     dp[0] = 1;
  13.     for(int i = 0; i <n; i++){
  14.         int a;
  15.         cin>>a;
  16.         ans+= dp[(sum+a)%k];
  17.         sum = (sum+a)%k;
  18.         dp[sum]++;
  19.     }
  20.     cout<<"Case "<<h<<": "<<ans<<endl;
  21.     }
  22.     return 0;
  23. }
  24.  

No comments:

Post a Comment

Most Featured Post

Lightoj 1159 - Batman

http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...