fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. struct state {
  7. int x, y, z, t;
  8. state() {
  9. x = y = z = t = -1;
  10. }
  11. state(int x, int y, int z, int t) :
  12. x(x), y(y), z(z), t(t) {
  13. }
  14. bool operator<(const state &e) const {
  15. return t < e.t;
  16. }
  17. };
  18.  
  19. const int N = 100;
  20. int n, m, k;
  21. int firstToSolve[N];
  22. vector<state> sub;
  23. int WA[N][N], FAC[N];
  24.  
  25. int main(int argc, char **argv) {
  26. int T;
  27. scanf("%d", &T);
  28. while (T-- != 0) {
  29. scanf("%d%d%d", &n, &m, &k);
  30. int x, y, z, tm, ts;
  31. sub.clear();
  32. for (int i = 0; i < k; ++i) {
  33. scanf("%d%d%d%d:%d", &x, &y, &z, &tm, &ts);
  34. sub.push_back(state(x - 1, y - 1, z, tm * 60 + ts));
  35. }
  36. sort(sub.begin(), sub.end());
  37. memset(firstToSolve, -1, sizeof firstToSolve);
  38. memset(WA, 0, sizeof WA);
  39. memset(FAC, 0, sizeof FAC);
  40. int ep = -1, sg = -1;
  41. pair<int, int> sp(-1, 0), rp(-1, 0);
  42. for (int i = 0; i < k; ++i) {
  43. if (sub[i].z == 0)
  44. ++WA[sub[i].x][sub[i].y];
  45. else {
  46. if (firstToSolve[sub[i].x] == -1)
  47. firstToSolve[sub[i].x] = sub[i].y + 1;
  48. if (ep == -1)
  49. ep = sub[i].y + 1;
  50. sg = sub[i].y + 1;
  51. if (WA[sub[i].x][sub[i].y] == 0)
  52. ++FAC[sub[i].y];
  53. if (FAC[sub[i].y] > sp.first || (FAC[sub[i].y] == sp.first && sub[i].y + 1 < sp.second))
  54. sp = make_pair(FAC[sub[i].y], sub[i].y + 1);
  55. if (WA[sub[i].x][sub[i].y] > rp.first || (WA[sub[i].x][sub[i].y] == rp.first && sub[i].y + 1 < rp.second))
  56. rp = make_pair(WA[sub[i].x][sub[i].y], sub[i].y + 1);
  57. }
  58. }
  59. for (int i = 0; i < n; ++i)
  60. printf("%s%d", i ? " " : "", firstToSolve[i]);
  61. puts("");
  62. printf("%d %d %d %d\n", ep, sg, sp.second, rp.second);
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0s 4392KB
stdin
1
6 6 13
1 1 1 005:23
1 4 1 007:49
1 5 1 008:21
1 2 1 010:32
3 1 0 012:18
3 1 1 013:20
1 6 1 016:20
1 3 1 018:46
2 3 0 029:14
2 3 1 037:14
5 1 0 042:37
2 2 1 044:35
5 1 1 055:29
stdout
1 3 1 -1 1 -1
1 1 2 1