Monday, August 10, 2015

UVa 10489 - Boxes of Chocolates

// UVa 10489 - Boxes of Chocolates

#include <iostream>
using namespace std;

int main() {
	int t;
	for (cin >> t; t; t--) {
		int n, b;
		cin >> n >> b;
		int sol = 0;
		for (; b; b--) {
			int k;
			cin >> k;
			int rem = (k > 0 ? 1 : 0);
			for (int i = 0; i < k; i++) {
				int a;
				cin >> a;
				rem = (rem * a) % n;
			}
			sol = (sol + rem) % n;
		}
		cout << sol << endl;
	}

	return 0;
}

No comments:

Post a Comment