제출 #879204

#제출 시각아이디문제언어결과실행 시간메모리
879204VovamatrixPlus Minus (BOI17_plusminus)C++14
100 / 100
38 ms7744 KiB
//https://oj.uz/problem/view/BOI17_plusminus #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define PI acos(-1) #define LSB(i) ((i) & -(i)) #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define sc second #define th third #define fo fourth #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double #define INF 1e15 #define MOD 1000000007 #define endl "\n" #define all(data) data.begin(),data.end() #define TYPEMAX(type) std::numeric_limits<type>::max() #define TYPEMIN(type) std::numeric_limits<type>::min() #define MAXK 100007 char s[MAXK]; ll x[MAXK],y[MAXK]; vector<pair<pll,ll>> vx,vy; ll Pow(ll a,ll b) { if(b==0) return 1; ll x=Pow(a,b/2)%MOD; x=(x*x)%MOD; if(b&1) x=(x*a)%MOD; return x; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,m,k,rez=0; cin>>n>>m>>k; for(int i=1;i<=k;i++) { cin>>s[i]>>y[i]>>x[i]; if(s[i]=='+') s[i]='1'; else s[i]='0'; vx.pb({{x[i],y[i]},i}); vy.pb({{y[i],x[i]},i}); } sort(all(vx)); sort(all(vy)); ll cnt=0,cur=0,curpar=-2; for(auto p:vy)// svi redovi su +- { if(p.fi.fi==cur) { if(curpar==-2) curpar=abs(p.fi.sc%2-(s[p.sc]-'0')); else if(curpar!=abs(p.fi.sc%2-(s[p.sc]-'0'))) {cnt=-1; break;} } else {cnt++; cur=p.fi.fi; curpar=abs(p.fi.sc%2-(s[p.sc]-'0'));}; } if(cnt!=-1) rez=(rez+Pow(2,n-cnt)); cnt=0; cur=0; curpar=-2; for(auto p:vx)// sve kolone su +- { if(p.fi.fi==cur) { if(curpar==-2) curpar=abs(p.fi.sc%2-(s[p.sc]-'0')); else if(curpar!=abs(p.fi.sc%2-(s[p.sc]-'0'))) {cnt=-1; break;} } else {cnt++; cur=p.fi.fi; curpar=abs(p.fi.sc%2-(s[p.sc]-'0'));}; } if(cnt!=-1) rez=(rez+Pow(2,m-cnt)); bool check=true; curpar=-2; for(int i=1;i<=k;i++) { if(curpar==-2) curpar=abs((x[i]+y[i])%2-(s[i]-'0')); else if(curpar!=abs((x[i]+y[i])%2-(s[i]-'0'))) {check=false; break;} } if(k==0) rez=((rez-2)%MOD+MOD)%MOD; else if(check) rez=((rez-1)%MOD+MOD)%MOD; cout<<rez<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...