-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva-10616.cpp
52 lines (39 loc) · 1.16 KB
/
uva-10616.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//uva 10616
//Divisible Group Sums
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
int n, q;
int tcounter = 0;
while (true) {
cin >> n >> q;
if (n == 0 && q == 0)
break;
++tcounter;
vector <int> num(n);
for (int i = 0; i < n; ++i)
cin >> num[i];
cout << "SET " << tcounter << ":" << endl;
int qcounter = 0;
while (q--) {
int d, m;
cin >> d >> m;
++qcounter;
vector < vector <int> > arr(m, vector <int> (d, 0));
vector < vector <int> > tmp_arr(m, vector <int> (d, 0));
for (int i = 0; i < n; ++i){
for(int k = 0; k < m - 1; ++k)
for (int j = 0; j < d; ++j){
int rem = ((num[i] + j) % d + d) % d;//to avoid negative remainder
tmp_arr[k + 1][rem] += arr[k][j];
}
++tmp_arr[0][((num[i] % d) + d) % d];
arr = tmp_arr;
}
cout << "QUERY " << qcounter << ": " << arr[m - 1][0] << endl;
}
}
return 0;
}