제출 #879193

#제출 시각아이디문제언어결과실행 시간메모리
879193DAleksaPlus Minus (BOI17_plusminus)C++17
100 / 100
112 ms9808 KiB
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int add(int x, int y) { x += y; return (x >= mod ? x - mod : x); }
int mul(int x, int y) { return (x * 1LL * y) % mod; }

void sadd(int& x, int y) { x = add(x, y); }
void smul(int& x, int y) { x = mul(x, y); }

int pw(int a, int n) {
    if(n == 0) return 1;
    int x = pw(a, n / 2);
    smul(x, x);
    if(n % 2 == 1) smul(x, a);
    return x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    map<int, char> col, row;
    bool can_col = true, can_row = true;
    for(int i = 0; i < k; i++) {
        char c;
        int x, y;
        cin >> c >> x >> y;
        char temp = col[x];
        if(y % 2 == 1) col[x] = c;
        else col[x] = (c ^ '+' ^ '-');
        if(temp == (col[x] ^ '+' ^ '-')) can_col = false;
        temp = row[y];
        if(x % 2 == 1) row[y] = c;
        else row[y] = (c ^ '+' ^ '-');
        if(temp == (row[y] ^ '+' ^ '-')) can_row = false;
    }
    int ans = 0;
    if(can_col) {
        int cnt = col.size();
        sadd(ans, pw(2, n - cnt));
    }
    if(can_row) {
        int cnt = row.size();
        sadd(ans, pw(2, m - cnt));
    }
    ans -= (can_col && can_row);
    ans -= (k == 0);
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...