이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll mod=1e9+7;
ll binpow(ll a,ll b){
ll res=1;
while(b){
if(b&1){
res=res*a%mod;
}
a=a*a%mod;
b=b>>1;
}
return res;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,m,k;
cin>>n>>m>>k;
vector<array<ll,3>>a(k),b(k);
for(ll i=0;i<k;i++){
char c;
ll x,y;
cin>>c>>x>>y;
ll u=(c=='+');
a[i]={u,x,y};
b[i]={u,y,x};
}
sort(all(a));
sort(all(b));
ll ans=0;
ll r=0,leftR=n,leftC=m;
ll c[2][2];
bool ok=true;
for(ll i=0;i<k;){
memset(c,0,sizeof c);
c[a[i][0]][a[i][2]%2]++;
r=i;
while(r<k-1&&a[r+1][1]==a[r][1]){
r++;
c[a[r][0]][a[r][2]%2]++;
}
if(c[0][0]+c[1][1]==0){
leftR--;
}
else if(c[1][0]+c[0][1]==0){
leftR--;
}
else{
ok=false;
}
i=r+1;
}
if(ok) ans=binpow(2,leftR);
ok=true;
for(ll i=0;i<k;){
memset(c,0,sizeof c);
c[b[i][0]][b[i][2]%2]++;
r=i;
while(r<k-1&&b[r+1][1]==b[r][1]){
r++;
c[b[r][0]][b[r][2]%2]++;
}
if(c[0][0]+c[1][1]==0){
leftC--;
}
else if(c[1][0]+c[0][1]==0){
leftC--;
}
else{
ok=false;
}
i=r+1;
}
if(ok) ans=(ans+binpow(2,leftC))%mod;
memset(c,0,sizeof c);
for(ll i=0;i<k;i++){
c[a[i][0]][(a[i][1]+a[i][2])%2]++;
}
if(c[0][0]+c[1][1]==0){
ans--;
}
else if(c[0][1]+c[1][0]==0){
ans--;
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |