# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1116010 | Thanhs | Plus Minus (BOI17_plusminus) | C++17 | 1 ms | 336 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}
const int NM = 1e5 + 5;
const int mod = 1e9 + 7;
struct mi
{
int v;
mi() : v(0){}
mi(int _v) : v(_v)
{
if (v >= mod)
v -= mod;
}
int inv() const
{
int t = mod - 2, res = 1, tt = v;
while (t)
{
if (t & 1)
res = 1ll * res * tt % mod;
tt = 1ll * tt * tt % mod;
t >>= 1;
}
return res;
}
mi operator+(const mi& o)
{
return mi(v + o.v);
}
mi operator-(const mi& o)
{
return mi(v + mod - o.v);
}
mi operator*(const mi& o)
{
return mi(1ll * v * o.v % mod);
}
mi operator/(const mi& o)
{
return mi(1ll * v * o.inv() % mod);
}
mi& operator+=(const mi &o)
{
v += o.v;
if (v >= mod)
v -= mod;
return *this;
}
mi& operator-=(const mi &o)
{
v += mod - o.v;
if (v >= mod)
v -= mod;
return *this;
}
mi& operator*=(const mi& o)
{
v = 1ll * v * o.v % mod;
return *this;
}
mi& operator/=(const mi& o)
{
v = 1ll * v * o.inv() % mod;
return *this;
}
}dp[2], ans;
pair<int, int> a[NM];
int n, m, k;
bool b1, b2;
map<int, int> R, C;
mi bp(mi x, int y)
{
mi res = 1;
while (y)
{
if (y & 1)
res *= x;
x *= x;
y >>= 1;
}
return res;
}
void chet()
{
cout << 0;
exit(0);
}
bool check(map<int, int>& mp, bool x)
{
for (auto t : mp)
if (x != t.se)
return 0;
return 1;
}
void solve()
{
cin >> n >> m >> k;
for (int i = 1; i <= k; i++)
{
char c;
cin >> c >> a[i].fi >> a[i].se;
int t = (a[i].fi & 1) ^ (a[i].se & 1) ^ (c == '+');
if (R.find(a[i].fi) == R.end())
R[a[i].fi] = t;
else if (R[a[i].fi] != t)
b1 = 1;
if (C.find(a[i].se) == C.end())
C[a[i].se] = t;
else if (C[a[i].se] != t)
b2 = 1;
}
ans += bp(2, n - (int)(R.size())) * (!b2);
ans += bp(2, m - (int)(C.size())) * (!b1);
ans = ans - check(C, 0);
ans = ans - check(C, 1);
cout << ans.v;
}
signed main()
{
if (fopen("in.txt", "r"))
{
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
else if (fopen(name".inp", "r"))
{
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int tc = 1;
// cin >> tc;
while (tc--)
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |