이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long mypow(long long m,long long y){
if(y==0){
return 1;
}
long long p=mypow(m,(y>>1));
p*=p;
p%=mod;
if(y&1){
p*=m;
p%=mod;
}
return p;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
int k;
cin>>k;
map<int,int>mpr,mpc;
for(int i=0;i<k;i++){
int u,v;
char c;
cin>>c;
cin>>u>>v;
if(c=='+'){
if(v&1){
mpr[u]|=1;
}
else{
mpr[u]|=2;
}
if(u&1){
mpc[v]|=1;
}
else{
mpc[v]|=2;
}
}
else{
if(v&1){
mpr[u]|=2;
}
else{
mpr[u]|=1;
}
if(u&1){
mpc[v]|=2;
}
else{
mpc[v]|=1;
}
}
}
vector<pair<int,int>>allr,allc;
for(auto x:mpr){
allr.push_back(x);
}
for(auto x:mpc){
allc.push_back(x);
}
sort(allr.begin(),allr.end());
sort(allc.begin(),allc.end());
int first=1,canfirst=1;
for(auto x:allr){
if(x.second==3){
// cout<<x.first<<" "<<x.second<<"\n";
first=0;
}
}
//cout<<first<<"\n";
for(int i=1;i<(int)allr.size();i++){
if((allr[i].first-allr[i-1].first)&1){
if(allr[i].second==allr[i-1].second){
canfirst=0;
}
}
else{
if(allr[i].second!=allr[i-1].second){
canfirst=0;
}
}
}
long long res=0;
//cout<<first<<"ads \n";
if(first==1){
// cout<<(int)allr.size()<<"\n";
res+=mypow(2,n-((int)allr.size()));
if(canfirst==1){
if(k==0){
res+=mod-2;
res%=mod;
}
else{
res+=mod-1;
res%=mod;
}
}
}
int second=1;
for(auto x:allc){
if(x.second==3){
second=0;
}
}
if(second==1){
res+=mypow(2,m-((int)allc.size()));
}
res%=mod;
cout<<res<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |