fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5.  
  6. using pi = pair<int, int>;
  7. using vi = vector<int>;
  8. using vii = vector<pi>;
  9. using vvi = vector<vi>;
  10. using sii = set<pi>;
  11. using si = set<int>;
  12.  
  13.  
  14. int main() {
  15. int n; cin >> n;
  16. vvi marbles(n);
  17. for(int i = 0; i < n; ++i) {
  18. int k; cin >> k;
  19. marbles[i].resize(k);
  20. for(int j = 0; j < k; ++j) {
  21. cin >> marbles[i][j];
  22. }
  23. }
  24. set<pair<int, pair<int, int>>> d;
  25. long long answer = 0;
  26. long long modulo = 1e9 + 7;
  27. for(int i = 0; i < n; ++i) {
  28. d.insert({marbles[i][0], {i, 0}});
  29. }
  30. while(not d.empty()) {
  31. long long digiti = d.begin()->first;
  32. long long stacki = d.begin()->second.first;
  33. long long indexi = d.begin()->second.second;
  34. answer = (answer * 365 + digiti) % modulo;
  35. d.erase(d.begin());
  36. if((int)marbles[stacki].size() > indexi + 1) {
  37. d.insert({marbles[stacki][indexi + 1], {stacki, indexi + 1}});
  38. }
  39. }
  40. cout << (365 * answer) % modulo << endl;
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 15240KB
stdin
3
3 2 5 7
4 1 4 6 10
3 3 2 1
stdout
227712621