이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//-------------------------------------
//| -<{ Besme llahe Rahmane Rahim }>- |
//-------------------------------------
#include <bits/stdc++.h>
#define pb push_back
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define sz(x) (int)(x).size()
#define all(c) (c).begin(),(c).end()
using namespace std;
typedef long long ll;
//----------New Code!----------
const int N = 100005;
const ll mod = 1000000007;
ll n, m, k;
struct node{int c;ll x;ll y;};
node Datax[N];
node Datay[N];
bool cmpx(node u, node v){return u.x < v.x;}
bool cmpy(node u, node v){return u.y < v.y;}
void read(){
cin >> n >> m >> k;
for(int i = 0; i < k; i++)
{
char c;
cin >> c;
Datax[i].c = c == '+';
cin >> Datax[i].x >> Datax[i].y;
Datay[i] = Datax[i];
}
sort(Datax, Datax+k, cmpx);
sort(Datay, Datay+k, cmpy);
}
ll p(ll x, ll y){
if(y == 0)
return 1;
ll t = p(x, y/2)%mod;
t = (t * t)%mod;
if(y%2)
t = (t * x)%mod;
return t;
}
ll solve(){
ll C[2], R[2], kr = 0, kc = 0, ans = 0;
bool fail1 = false, fail2 = false;
for(int i = 0; i < k; i++)
{
if(i == 0)
kr = kc = 1;
if(Datax[i].x != Datax[i-1].x)
kr++;
if(Datay[i].y != Datay[i-1].y)
kc++;
}
for(int i = 0; i < k; i++)
{
if((i==0) || (i > 0 && Datax[i].x != Datax[i-1].x))
{
R[Datax[i].y%2] = Datax[i].c;
R[1-(Datax[i].y%2)] = 1-Datax[i].c;
}
if(Datax[i].c != R[Datax[i].y%2])
fail1 = true;
}
if(!fail1) ans = p(2, n-kr);
for(int i = 0; i < k; i++)
{
if((i == 0) || (i > 0 && Datay[i].y != Datay[i-1].y))
{
C[Datay[i].x%2] = Datay[i].c;
C[1-(Datay[i].x%2)] = 1-Datay[i].c;
}
if(Datay[i].c != C[Datay[i].x%2])
fail2 = true;
}
if(!fail2) ans += p(2, m-kc);
if(!fail1 && !fail2) ans--;
if(k == 0) ans--;
if(ans < 0) ans += mod;
return ans%mod;
}
int main(){
read();
cout << solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |