Submission #7339261


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    if (i != 0) { a[i] += a[i-1]; }
    a[i] %= m;
  }

  map<int, int> mp;
  ll ans = 0;

  for (int i = 0; i < n; i++) {
    mp[a[i]]++;
    if (a[i] == 0) {
      ans += mp[0];
    } else {
      ans += mp[a[i]] - 1;
    }
  }

  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task D - Candy Distribution
User kira924age
Language C++14 (GCC 5.4.1)
Score 400
Code Size 604 Byte
Status
Exec Time 36 ms
Memory 3584 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 400 / 400 0_min0, 0_min1, 1_small0, 1_small1, 1_small2, 2_large0, 2_large1, 2_large2, 2_large3, 2_large4, 2_large5, 2_large6, 2_large7, 2_large8, 2_large9, 3_max0, 3_max1, 3_max2, 3_max3, 3_max4, 3_max5, 3_max6, 3_max7, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_min0 1 ms 256 KB
0_min1 1 ms 256 KB
1_small0 1 ms 256 KB
1_small1 1 ms 256 KB
1_small2 1 ms 256 KB
2_large0 2 ms 256 KB
2_large1 21 ms 896 KB
2_large2 19 ms 640 KB
2_large3 10 ms 512 KB
2_large4 17 ms 640 KB
2_large5 2 ms 384 KB
2_large6 8 ms 640 KB
2_large7 7 ms 512 KB
2_large8 1 ms 256 KB
2_large9 4 ms 384 KB
3_max0 36 ms 3584 KB
3_max1 22 ms 896 KB
3_max2 13 ms 640 KB
3_max3 9 ms 640 KB
3_max4 9 ms 640 KB
3_max5 9 ms 640 KB
3_max6 14 ms 640 KB
3_max7 14 ms 640 KB
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB