Submission #1275848

#TimeUsernameProblemLanguageResultExecution timeMemory
1275848PooyaDaftarianPlus Minus (BOI17_plusminus)C++20
100 / 100
98 ms12956 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0)
#define endl '\n'
#define pb push_back
#define out(x) {cout << x << '\n'; return 0;}
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define int ll

const int mod = 1e9+7;

int pw(int a, int b){
    int ans = 1;
    while (b){
        if (b&1) (ans *= a) %= mod;
        (a *= a) %= mod;
        b >>= 1;
    }
    return ans;
}

int32_t main(){
    fast_io;
    int n, m, k; cin >> n >> m >> k;
    map<int, bool> mpr, mpc;
    int r = 1, c = 1;
    while (k--){
        char ch; int x, y; cin >> ch >> x >> y;
        bool b = (ch == '+'); bool d = (x%2) ^ (y%2) ^ b;
        if (mpr.find(x) != mpr.end()){
            if (mpr[x] != d) r = 0;
        } else mpr[x] = d;
        if (mpc.find(y) != mpc.end()){
            if (mpc[y] != d) c = 0;
        } else mpc[y] = d;
    }
    if (!r && !c) out(0);
    bool f0 = 1, f1 = 1;
    for (auto [x, v] : mpr)
        f0 &= (v == 0), f1 &= (v == 1);
    cout << (pw(2, n-sz(mpr)) * r + pw(2, m-sz(mpc)) * c - f0 - f1 + mod) % mod << endl;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...