Submission #559191

#TimeUsernameProblemLanguageResultExecution timeMemory
559191SweezyPlus Minus (BOI17_plusminus)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL #include "algo/debug.h" #else #define debug(...) 42 #endif #define all(a) (a).begin(), (a).end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define reps(i, s, n) for (int i = s; i < (n); ++i) #define pb push_back #define sz(a) (int) (a.size()) const int mod = 1e9 + 7; int power(int a, int n) { int res = 1; while (n) { if (n % 2) { (res *= a) %= mod; } (a *= a) %= mod; n /= 2; } return res; } // typedef vector<vector<int>> matrix; // matrix mul(matrix a, matrix b) { // matrix res(sz(a), vector<int> (sz(b[0]))); // rep(i, sz(a)) { // rep(j, sz(b[0])) { // rep(k, sz(a[0])) { // (res[i][j] += a[i][k] * b[k][j]) %= mod; // } // } // } // return res; // } // matrix matpow(matrix a, int s, int n) { // matrix res(s, vector<int> (s)); // rep(i, s) { // res[i][i] = 1; // } // while (n) { // if (n & 1) { // res = mul(res, a); // } // a = mul(a, a); // n /= 2; // } // return res; // } void solve() { int n, m, k; cin >> n >> m >> k; vector<int> x(k), y(k), t(k); rep(i, k) { char c; cin >> c >> x[i] >> y[i]; t[i] = (c == '+'); --x[i], --y[i]; } if(k == 0){ cout << (power(2, n) + power(2, m) - 2 + 5 * mod) % mod; return; } // matrix transition{{1, 1}, {1, 0}}; if (n == 1 || m == 1) { cout << power(2, n * m - k); return; } bool need = 0; int res = 0; auto add = [&] () -> void { map<int, int> mp; rep(i, k) { int type = (t[i] == 1 ? (x[i] & 1) : (x[i] & 1 ^ 1)); if (mp.find(y[i]) != mp.end() && mp[y[i]] != type) { return; } mp[y[i]] = type; } res += power(2, m - sz(mp)); bool del = 1; int prv = -1, prv_type = -1; for (auto &[y, type] : mp) { if (prv != -1) { del &= (y - prv) % 2 == ((type == prv_type) ^ 1); } } need |= del; }; add(); debug(res); rep(i, k) { int xx = x[i]; int yy = y[i]; y[i] = n - 1 - xx; x[i] = yy; } swap(n, m); add(); debug(res); if (need) { res -= 1; if (res < 0) { res += mod; } } cout << res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }

Compilation message (stderr)

plusminus.cpp: In lambda function:
plusminus.cpp:89:50: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   89 |       int type = (t[i] == 1 ? (x[i] & 1) : (x[i] & 1 ^ 1));
plusminus.cpp: In function 'void solve()':
plusminus.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 42
      |                    ^~
plusminus.cpp:106:3: note: in expansion of macro 'debug'
  106 |   debug(res);
      |   ^~~~~
plusminus.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 42
      |                    ^~
plusminus.cpp:115:3: note: in expansion of macro 'debug'
  115 |   debug(res);
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...