Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <vector>
- #include <set>
- #include <map>
- #include <utility>
- #include <cstdlib>
- #include <memory>
- #include <queue>
- #include <cassert>
- #include <cmath>
- #include <ctime>
- #include <complex>
- #include <bitset>
- #include <fstream>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define pb push_back
- #define fst first
- #define snd second
- #define mp make_pair
- #define sz(C) ((int) (C).size())
- #define forn(i, n) for (int i = 0; i < (int) n; ++i)
- #define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
- #define y1 gftxdtrtfhyjfctrxujkvbhyjice
- #define y0 ehfoiuvhefroerferjhfjkehfjke
- #define left sdhfsjkshdjkfsdfgkqqweqweh
- #define right yytrwtretywretwreytwreytwr
- #define next jskdfksdhfjkdsjksdjkgf
- #define prev koeuigrihjdkjdfj
- #define hash kjfdkljkdhgjdkfhgurehg
- #define all(C) begin(C), end(C)
- #define is_empty slkdjflksdjfkl
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int uint;
- typedef pair <int,int> pii;
- typedef pair <ll, ll> pll;
- typedef vector <ll> vll;
- typedef vector <int> vi;
- typedef vector <vector <int> > vvi;
- typedef vector <pii> vii;
- typedef long double ld;
- typedef complex<double> cd;
- typedef vector<cd> vcd;
- #define FILE_NAME ""
- const ld EPS = 1e-9;
- const string field[15] = {
- "rwwgwwwrwwwgwwr",
- "wbwwwywwwywwwbw",
- "wwbwwwgwgwwwbww",
- "gwwbwwwgwwwbwwg",
- "wwwwbwwwwwbwwww",
- "wywwwwwwwwwwwyw",
- "wwgwwwgwgwwwgww",
- "rwwgwwwswwwgwwr",
- "wwgwwwgwgwwwgww",
- "wywwwwwwwwwwwyw",
- "wwwwbwwwwwbwwww",
- "gwwbwwwgwwwbwwg",
- "wwbwwwgwgwwwbww",
- "wbwwwywwwywwwbw",
- "rwwgwwwrwwwgwwr"
- };
- map<char, int> letter_coef;
- map<char, int> word_coef;
- 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 };
- bool is_empty[15][15];
- void init() {
- letter_coef = { { 'w', 1 }, { 's', 1 }, { 'g', 2 }, { 'y', 3 }, { 'b', 1 }, { 'r', 1 } };
- word_coef = { { 'w', 1 }, { 's', 1 }, { 'g', 1 }, { 'y', 1 }, { 'b', 2 }, { 'r', 3 } };
- memset (is_empty, true, sizeof is_empty);
- }
- vii get_path(char dir, int r, int c, int L) {
- vii path;
- if (dir == 'h') {
- for (int j = c; j < c + L; ++j) {
- path.pb(mp(r, j));
- }
- } else {
- assert(dir == 'v');
- for (int i = r; i < r + L; ++i) {
- path.pb(mp(i, c));
- }
- }
- return path;
- }
- int cnt_empty(const vii& path) {
- int cnt = 0;
- for (auto p : path) {
- cnt += is_empty[p.fst][p.snd];
- }
- return cnt;
- }
- void put(const vii& path) {
- for (auto p : path) {
- is_empty[p.fst][p.snd] = false;
- }
- }
- int main() {
- //#ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- //#endif
- init();
- int n, m;
- scanf("%d%d", &n, &m);
- vi sum(n, 0);
- forn(i, m) {
- int who = i % n;
- int w;
- scanf("%d", &w);
- int cnt_new = 0;
- forn(j, w) {
- int L;
- scanf("%d ", &L);
- char dir = getchar();
- assert(dir == 'v' || dir == 'h');
- int col, row;
- scanf("%d%d", &col, &row);
- --col;
- --row;
- vi word(L);
- forn(i, L) {
- scanf("%d", &word[i]);
- --word[i];
- }
- vii path = get_path(dir, row, col, L);
- assert(sz(path) == L);
- int cost = 0;
- cnt_new += cnt_empty(path);
- int prod_coef_word = 1;
- int sum_letters = 0;
- forn(i, sz(path)) {
- auto p = path[i];
- sum_letters += price[word[i]] * letter_coef[field[p.fst][p.snd]];
- prod_coef_word *= word_coef[field[p.fst][p.snd]];
- }
- cost += sum_letters * prod_coef_word;
- sum[who] += cost;
- put(path);
- }
- if (cnt_new == 7) {
- sum[who] += 15;
- }
- }
- forn(i, n) {
- printf("%d\n", sum[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement