Advertisement
Guest User

Untitled

a guest
Oct 4th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <vector>
  7. #include <set>
  8. #include <map>
  9. #include <utility>
  10. #include <cstdlib>
  11. #include <memory>
  12. #include <queue>
  13. #include <cassert>
  14. #include <cmath>
  15. #include <ctime>
  16. #include <complex>
  17. #include <bitset>
  18. #include <fstream>
  19. #include <unordered_map>
  20. #include <unordered_set>
  21.  
  22. using namespace std;
  23.  
  24. #define pb push_back
  25. #define fst first
  26. #define snd second
  27. #define mp make_pair
  28. #define sz(C) ((int) (C).size())
  29. #define forn(i, n) for (int i = 0; i < (int) n; ++i)
  30. #define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
  31. #define y1 gftxdtrtfhyjfctrxujkvbhyjice
  32. #define y0 ehfoiuvhefroerferjhfjkehfjke
  33. #define left sdhfsjkshdjkfsdfgkqqweqweh
  34. #define right yytrwtretywretwreytwreytwr
  35. #define next jskdfksdhfjkdsjksdjkgf
  36. #define prev koeuigrihjdkjdfj
  37. #define hash kjfdkljkdhgjdkfhgurehg
  38. #define all(C) begin(C), end(C)
  39. #define is_empty slkdjflksdjfkl
  40.  
  41. typedef long long ll;
  42. typedef unsigned long long ull;
  43. typedef unsigned int uint;
  44. typedef pair <int,int> pii;
  45. typedef pair <ll, ll> pll;
  46. typedef vector <ll> vll;
  47. typedef vector <int> vi;
  48. typedef vector <vector <int> > vvi;
  49. typedef vector <pii> vii;
  50. typedef long double ld;
  51. typedef complex<double> cd;
  52. typedef vector<cd> vcd;
  53.  
  54. #define FILE_NAME ""
  55.  
  56. const ld EPS = 1e-9;
  57.  
  58. const string field[15] = {
  59.   "rwwgwwwrwwwgwwr",
  60.     "wbwwwywwwywwwbw",
  61.     "wwbwwwgwgwwwbww",
  62.     "gwwbwwwgwwwbwwg",
  63.     "wwwwbwwwwwbwwww",
  64.     "wywwwwwwwwwwwyw",
  65.     "wwgwwwgwgwwwgww",
  66.     "rwwgwwwswwwgwwr",
  67.     "wwgwwwgwgwwwgww",
  68.     "wywwwwwwwwwwwyw",
  69.     "wwwwbwwwwwbwwww",
  70.     "gwwbwwwgwwwbwwg",
  71.     "wwbwwwgwgwwwbww",
  72.     "wbwwwywwwywwwbw",
  73.     "rwwgwwwrwwwgwwr"  
  74. };
  75.  
  76. map<char, int> letter_coef;
  77. map<char, int> word_coef;
  78.  
  79. const int price[32] = { 1, 3, 2, 3, 2, 1, 5, 5, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 3, 10, 5, 10, 5, 10, 10, 10, 5, 5, 10, 10, 3 };
  80.  
  81. bool is_empty[15][15];
  82.  
  83. void init() {
  84.   letter_coef = { { 'w', 1 }, { 's', 1 }, { 'g', 2 }, { 'y', 3 }, { 'b', 1 }, { 'r', 1 } };
  85.   word_coef = { { 'w', 1 }, { 's', 1 }, { 'g', 1 }, { 'y', 1 }, { 'b', 2 }, { 'r', 3 } };
  86.   memset (is_empty, true, sizeof is_empty);
  87. }
  88.  
  89. vii get_path(char dir, int r, int c, int L) {
  90.   vii path;
  91.   if  (dir == 'h') {
  92.     for (int j = c; j < c + L; ++j) {
  93.       path.pb(mp(r, j));
  94.     }
  95.   } else {
  96.     assert(dir == 'v');
  97.     for (int i = r; i < r + L; ++i) {
  98.       path.pb(mp(i, c));
  99.     }
  100.   }
  101.   return path;
  102. }
  103.  
  104. int cnt_empty(const vii& path) {
  105.   int cnt = 0;
  106.   for (auto p : path) {
  107.     cnt += is_empty[p.fst][p.snd];
  108.   }
  109.   return cnt;
  110. }
  111.  
  112. void put(const vii& path) {
  113.   for (auto p : path) {
  114.     is_empty[p.fst][p.snd] = false;
  115.   }
  116. }
  117.  
  118. int main() {
  119. //#ifdef LOCAL
  120.   freopen("input.txt", "r", stdin);
  121.   freopen("output.txt", "w", stdout);
  122. //#endif
  123.  
  124.   init();
  125.  
  126.   int n, m;
  127.   scanf("%d%d", &n, &m);
  128.  
  129.   vi sum(n, 0);
  130.   forn(i, m) {
  131.     int who = i % n;
  132.     int w;
  133.     scanf("%d", &w);
  134.     int cnt_new = 0;
  135.     forn(j, w) {
  136.       int L;
  137.       scanf("%d ", &L);
  138.       char dir = getchar();
  139.       assert(dir == 'v' || dir == 'h');
  140.       int col, row;
  141.       scanf("%d%d", &col, &row);
  142.       --col;
  143.       --row;
  144.       vi word(L);
  145.       forn(i, L) {
  146.         scanf("%d", &word[i]);
  147.         --word[i];
  148.       }
  149.       vii path = get_path(dir, row, col, L);
  150.       assert(sz(path) == L);
  151.       int cost = 0;
  152.       cnt_new += cnt_empty(path);
  153.       int prod_coef_word = 1;
  154.       int sum_letters = 0;
  155.       forn(i, sz(path)) {
  156.         auto p = path[i];
  157.         sum_letters += price[word[i]] * letter_coef[field[p.fst][p.snd]];
  158.         prod_coef_word *= word_coef[field[p.fst][p.snd]];  
  159.       }
  160.       cost += sum_letters * prod_coef_word;
  161.       sum[who] += cost;
  162.       put(path);
  163.     }
  164.     if  (cnt_new == 7) {
  165.       sum[who] += 15;
  166.     }
  167.   }
  168.  
  169.   forn(i, n) {
  170.     printf("%d\n", sum[i]);
  171.   }
  172.  
  173.   return 0;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement