# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879194 | StefanSebez | Plus Minus (BOI17_plusminus) | C++14 | 0 ms | 348 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 fi first
#define se second
#define ll long long
const int mod=1e9+7;
map<int,int>mapa;
ll Plus(ll a,ll b)
{
a%=mod,b%=mod;
ll x=a+b;x%=mod;return x;
}
ll Puta(ll a,ll b)
{
a%=mod,b%=mod;
ll x=a*b;x%=mod;return x;
}
int main()
{
int n,m,k;scanf("%i%i%i",&n,&m,&k);
pair<pair<int,int>,int>a[k+10];
bool bul1=true,bul2=true;
for(int i=1;i<=k;i++)
{
char c;cin>>c;
int t=1;if(c=='+') t=2;
scanf("%i%i",&a[i].fi.fi,&a[i].fi.se);
if((a[i].fi.fi+a[i].fi.se)%2==0) bul1=false;
else bul2=false;
a[i].se=t;
}
ll res=0;
sort(a+1,a+k+1);
bool bul=true;
int ct=n;
for(int i=1;i<=k;i++)
{
int t=((a[i].fi.se-1)%2+a[i].se-1)%2+1;
if((mapa[a[i].fi.fi]==1 && t==2) || (mapa[a[i].fi.fi]==2 && t==1)) bul=false;
if(mapa[a[i].fi.fi]==0) ct--;
mapa[a[i].fi.fi]=t;
}
ll e=1;
for(int i=1;i<=ct;i++) e=Puta(e,2);
if(bul && ct>0) res=Plus(res,e);
for(int i=1;i<=k;i++)
{
swap(a[i].fi.fi,a[i].fi.se);
}
mapa.clear();
sort(a+1,a+k+1);
bul=true;
ct=m;
for(int i=1;i<=k;i++)
{
int t=((a[i].fi.se-1)%2+a[i].se-1)%2+1;
if((mapa[a[i].fi.fi]==1 && t==2) || (mapa[a[i].fi.fi]==2 && t==1)) bul=false;
if(mapa[a[i].fi.fi]==0) ct--;
mapa[a[i].fi.fi]=t;
}
//printf("%i\n",ct);
e=1;
for(int i=1;i<=ct;i++) e=Puta(e,2);
if(bul && ct>0) res=Plus(res,e);
if(bul1==true) res--;
if(bul2==true) res--;
if(res<0) res+=mod;
printf("%lld\n",res);
return 0;
}
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... |