Submission #714685

#TimeUsernameProblemLanguageResultExecution timeMemory
714685KINGPlus Minus (BOI17_plusminus)C++14
100 / 100
216 ms19956 KiB
#include<bits/stdc++.h>
#define NOT_STONKS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
const int maxn = 2e5 + 10; //4e6 + 10; //3e5 + 10;
const int mod = 1e9 + 7; //998244353;
typedef long long ll;

int n, m, k;
map<int, bool> br, bc, mpr, mpc; 
ll ans = 0;

ll power(ll x, int y) {
    if (y == 0) return 1;
    if (y == 1) return x;
    ll tmp = power(x, y >> 1);
    if (y & 1)
        return tmp * tmp % mod * x % mod;
    return tmp * tmp % mod;
}

int main() {
    NOT_STONKS;

    cin >> n >> m >> k;
    bool R = true, C = true, lanat_be = true, in_zendegi = true;
    for (int i = 0; i < k; i++) {
        int x, y;
        char c;
        cin >> c >> x >> y;
        int tx = x, ty = y;
        if (c == '-') ty ^= 1, tx ^= 1, lanat_be &= (x + y) & 1, in_zendegi &= (x + y) & 1 ^ 1;
        else lanat_be &= (x + y) & 1 ^ 1, in_zendegi &= (x + y) & 1;
        if (!br[x]) br[x] = true, mpr[x] = ty & 1;
        else R &= (mpr[x] & 1) == (ty & 1);
        if (!bc[y]) bc[y] = true, mpc[y] = tx & 1;
        else C &= (mpc[y] & 1) == (tx & 1);
    }
    
    if (R) ans += power(2, n - int(mpr.size())), ans %= mod;
    if (C) ans += power(2, m - int(mpc.size())), ans %= mod;
    
    ans -= (lanat_be + in_zendegi);
    cout << ans << endl;
    return 0;
}

Compilation message (stderr)

plusminus.cpp: In function 'int main()':
plusminus.cpp:32:88: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   32 |         if (c == '-') ty ^= 1, tx ^= 1, lanat_be &= (x + y) & 1, in_zendegi &= (x + y) & 1 ^ 1;
      |                                                                                ~~~~~~~~^~~
plusminus.cpp:33:34: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   33 |         else lanat_be &= (x + y) & 1 ^ 1, in_zendegi &= (x + y) & 1;
      |                          ~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...