bitmasks brute force combinatorics constructive algorithms math

Please click on ads to support us..

C++ Code:

// Problem: G. Turtle Magic: Royal Turtle Shell Pattern
// Contest: Codeforces - Codeforces Round 929 (Div. 3)
// URL: https://codeforces.com/contest/1933/problem/G
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
void solve() {
  ll n, m, q;
  cin >> n >> m >> q;
  string s1(2, '#'), s2(2, '#');
  bool failed = false;
  int ans = 0;
  cout << 8 << '\n';
  while (q--) {
    int r, c;
    string shape;
    cin >> r >> c >> shape;
    --r, --c;
    // cerr << "r=" << r << ",c=" << c << ",shape=" << shape << endl;
    char ch = shape[0];
    
    auto check = [] (int x, int y, string &dir, char ch) {
      // cerr << "x=" << x << ",y=" << y << ",ch=" << ch << endl;
      int target = x % 2;
      int rev = ((x / 2 - y) % 2 + 2) % 2;
      if (rev == 1) {
        if (ch == 'c') {
          ch = 's';
        } else {
          ch = 'c';
        }
      }
      // cerr << "target=" << target << ",ch=" << ch << endl;
      if (dir[target] == '#') {
        dir[target] = ch;
      } else if (dir[target] == ch) {
        
      } else {
        dir = "ff";
      }
    };
    check(r, c, s1, ch);
    check(c, r, s2, ch);
    // cerr << "s1=" << s1 << ",s2=" << s2 << endl;
    int ans = 0;
    for (auto &h : {s1, s2}) {
      if (h == "ff") {
        continue;
      }
      int tmp = 1;
      for (auto x : h) {
        if (x == '#') tmp *= 2;
      }
      ans += tmp;
    }
    cout << ans << '\n';
  }
}

int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
  }
}


Comments

Submit
0 Comments
More Questions

137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park
342A - Xenia and Divisors
1033A - King Escape
39D - Cubical Planet
1453A - Cancel the Trains
645A - Amity Assessment
1144A - Diverse Strings
1553B - Reverse String
1073A - Diverse Substring
630N - Forecast
312B - Archer
34D - Road Map
630I - Parking Lot
160B - Unlucky Ticket
371B - Fox Dividing Cheese
584B - Kolya and Tanya
137B - Permutation