Submission #132512

#TimeUsernameProblemLanguageResultExecution timeMemory
132512tlwpdusPlus Minus (BOI17_plusminus)C++11
100 / 100
67 ms1912 KiB
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef long long ll; typedef pair<int,int> pii; const ll MOD = 1e9+7; int n, m, k; pii arr[100100]; int sgn[100100]; int ord[100100]; ll po(ll a, ll n) { if (!n) return 1; ll t = po(a,n/2); return t*t%MOD*(n%2?a:1)%MOD; } ll solve() { iota(ord,ord+k,0); sort(ord,ord+k,[](int a, int b){return arr[a]<arr[b];}); int p = 0, mang = 0, num = (k?1:0); for (int i=0;i<k;i++) { if (arr[ord[i]].x==arr[ord[p]].x) { if ((arr[ord[i]].y^sgn[ord[i]])%2!=(arr[ord[p]].y^sgn[ord[p]])%2) mang=1; } else { p = i; num++; } } return mang?0:po(2,n-num); } int main() { scanf("%d%d%d",&n,&m,&k); for (int i=0;i<k;i++) { char c; int a, b; scanf(" %c%d%d",&c,&a,&b); sgn[i] = (c=='+'?1:0); arr[i] = {a,b}; } ll ans = solve(); swap(n,m); for (int i=0;i<k;i++) swap(arr[i].x,arr[i].y); ans += solve(); if (!k) ans+=MOD-2; else { int mang = 0; for (int i=0;i<k;i++) { if ((arr[i].x^arr[i].y^sgn[i])%2!=(arr[0].x^arr[0].y^sgn[0])%2) mang = 1; } if (!mang) ans+=MOD-1; } printf("%lld\n",ans%MOD); return 0; }

Compilation message (stderr)

plusminus.cpp: In function 'int main()':
plusminus.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
plusminus.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d%d",&c,&a,&b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...