Submission #935245

#TimeUsernameProblemLanguageResultExecution timeMemory
935245irmuunPlus Minus (BOI17_plusminus)C++17
100 / 100
40 ms7248 KiB
#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]={x,y,u}; b[i]={y,x,u}; } 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][2]][a[i][1]%2]++; r=i; while(r<k-1&&a[r+1][0]==a[r][0]){ r++; c[a[r][2]][a[r][1]%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][2]][b[i][1]%2]++; r=i; while(r<k-1&&b[r+1][0]==b[r][0]){ r++; c[b[r][2]][b[r][1]%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][2]][(a[i][0]+a[i][1])%2]++; } if(c[0][0]+c[1][1]==0){ ans--; } if(c[0][1]+c[1][0]==0){ ans--; } if(ans<0) ans+=mod; cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...