Submission #536302

#TimeUsernameProblemLanguageResultExecution timeMemory
536302StickfishPlus Minus (BOI17_plusminus)C++17
12 / 100
1 ms212 KiB
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

const ll MOD = 1000000007;

ll pw(ll a, ll m) {
    if (!m)
        return 1;
    if (m % 2)
        return pw(a, m - 1) * a % MOD;
    return pw(a * a % MOD, m >> 1);
}

signed main() {
    ll n, m, k;
    cin >> n >> m >> k;
    map<ll, ll> mprow;
    map<ll, ll> mpcellar;
    bool row = true, cellar = true;
    ll chess = -1;
    for (ll aa = 0; aa < k; ++aa) {
        char c, i, j;
        cin >> c >> i >> j;
        int t = int(c == '+');
        if (mprow.find(i) != mprow.end() && mprow[i] != (j + t) % 2)
            row = false;
        else
            mprow[i] = (j + t) % 2;
        if (mpcellar.find(j) != mpcellar.end() && mpcellar[j] != (i + t) % 2)
            cellar = false;
        else
            mpcellar[j] = (i + t) % 2;
        if (chess == -1 || chess == (i + j + t) % 2)
            chess = (i + j + t) % 2;
        else
            chess = -2;
    }
    ll ans = 0;
    if (row)
        ans += pw(2, n - mprow.size());
    if (cellar)
        ans += pw(2, m - mpcellar.size());
    if (row && cellar) {
        if (chess == -1) {
            ans += MOD - 2;
        } else if (chess != -2) {
            ans += MOD - 1;
        }
    }
    ans %= MOD;
    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...