이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/extc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,m,k,ans,mod=1e9+7;
map<int,vector<int>> row,col;
int dopow(int x, int y){
if(y==0){
return 1;
}
int z = dopow(x,y/2);
if(y%2){
return (((z*z)%mod)*x)%mod;
}
else{
return (z*z)%mod;
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for(int i=1;i<=k;i++){
char a;
int b,c;
cin >> a >> b >> c;
if(a=='-'){
row[b].push_back(c+1);
col[c].push_back(b+1);
}
else{
row[b].push_back(c);
col[c].push_back(b);
}
}
bool isrow=true,iscol=true;
for(auto it=row.begin();it!=row.end();it++){
int p = (it->second)[0];
for(int i:(it->second)){
if(i%2!=p%2){
isrow = false;
}
}
}
for(auto it=col.begin();it!=col.end();it++){
int p = (it->second)[0];
for(int i:(it->second)){
if(i%2!=p%2){
iscol = false;
}
}
}
if(isrow and iscol){
ans = dopow(2,n-row.size());
ans += dopow(2,m-col.size());
ans--;
ans %= mod;
}
else if(isrow){
ans = dopow(2,n-row.size());
}
else if(iscol){
ans = dopow(2,m-col.size());
}
if(k==0){
ans--;
}
cout << ans << "\n";
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... |