Submission #129901

# Submission time Handle Problem Language Result Execution time Memory
129901 2019-07-13T13:29:01 Z Abelyan Plus Minus (BOI17_plusminus) C++17
100 / 100
129 ms 15084 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define all(v) v.begin(),v.end()
#define ad push_back
#define fr first
#define sc second
#define mpr(a,b) make_pair(a,b)
#define pir pair<int,int>
#define all(v) v.begin(),v.end()
#define make_unique(v) v.erase(unique(all(v)),v.end())
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define y1 EsiHancagorcRepa
 
const int N=1e5+10;
const ll MOD=1e9+7;
 
vector<pair<int,char> > tox[N],syun[N];
vector<int> v1,v2;
int x[N],y[N];
char c[N];
 
ll pw(ll a,int x){
    //cout<<x<<endl;
    if (x==0)return 1;
    ll k=pw(a,x/2);
    k=(k*k)%MOD;
    if (x%2){
        return (a*k)%MOD;
    }
    return k;
}
 
int main(){
    fastio;
    srng;
    int n,m,k;
    cin>>n>>m>>k;
    ll ans;
    if (k==0){
        ans=pw(2,n)+pw(2,m)+MOD-2;
        ans%=MOD;
        cout<<ans<<endl;
        return 0;
    }
    int mn;
    char sk;
    int han=1;
    FOR(i,k){
        cin>>c[i]>>x[i]>>y[i];
        x[i]--;
        y[i]--;
        if (i==0){
            mn=(x[i]+y[i])%2;
            sk=c[i];
        }
        else if(((x[i]+y[i])%2==mn)!=(c[i]==sk)){
            han=0;
        }
 
        v1.ad(x[i]);
        v2.ad(y[i]);
    }
    sort(all(v1));
    make_unique(v1);
    sort(all(v2));
    make_unique(v2);
    FOR(i,k){
        int k1=x[i]%2,k2=y[i]%2;
        x[i]=lower_bound(all(v1),x[i])-v1.begin();
        y[i]=lower_bound(all(v2),y[i])-v2.begin();
        tox[x[i]].ad(mpr(k2,c[i]));
        syun[y[i]].ad(mpr(k1,c[i]));
    }
    //cout<<1<<endl;
    ll txans=1,syunans=1;
    FOR(i,v1.size()){
        bool bl=true;
        FOR(j,tox[i].size()){
            if ((tox[i][0].fr%2==tox[i][j].fr%2)!=(tox[i][0].sc==tox[i][j].sc))bl=false;
        }
        if (!bl)txans=0;
    }
    FOR(i,v2.size()){
        bool bl=true;
        FOR(j,syun[i].size()){
            if ((syun[i][0].fr%2==syun[i][j].fr%2)!=(syun[i][0].sc==syun[i][j].sc))bl=false;
        }
        if (!bl)syunans=0;
    }
 
    txans=txans*pw(2,n-v1.size());
    txans%=MOD;
    syunans=syunans*pw(2,m-v2.size());
    syunans%=MOD;
    ans=txans+syunans-han+MOD;
    //cout<<syunans<<endl;
    cout<<ans%MOD<<endl;
    return 0;
}

Compilation message

plusminus.cpp: In function 'int main()':
plusminus.cpp:8:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a) for (int i=0;i<(a);++i)
                                ^
plusminus.cpp:87:5: note: in expansion of macro 'FOR'
     FOR(i,v1.size()){
     ^~~
plusminus.cpp:8:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a) for (int i=0;i<(a);++i)
                                ^
plusminus.cpp:89:9: note: in expansion of macro 'FOR'
         FOR(j,tox[i].size()){
         ^~~
plusminus.cpp:8:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a) for (int i=0;i<(a);++i)
                                ^
plusminus.cpp:94:5: note: in expansion of macro 'FOR'
     FOR(i,v2.size()){
     ^~~
plusminus.cpp:8:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a) for (int i=0;i<(a);++i)
                                ^
plusminus.cpp:96:9: note: in expansion of macro 'FOR'
         FOR(j,syun[i].size()){
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5080 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4984 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5080 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4984 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 7 ms 5112 KB Output is correct
12 Correct 6 ms 4988 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 65 ms 9832 KB Output is correct
17 Correct 63 ms 9836 KB Output is correct
18 Correct 64 ms 9932 KB Output is correct
19 Correct 62 ms 9964 KB Output is correct
20 Correct 62 ms 9836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 5080 KB Output is correct
4 Correct 6 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Correct 6 ms 4984 KB Output is correct
8 Correct 6 ms 4984 KB Output is correct
9 Correct 6 ms 4984 KB Output is correct
10 Correct 6 ms 4984 KB Output is correct
11 Correct 7 ms 5112 KB Output is correct
12 Correct 6 ms 4988 KB Output is correct
13 Correct 6 ms 4984 KB Output is correct
14 Correct 8 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 65 ms 9832 KB Output is correct
17 Correct 63 ms 9836 KB Output is correct
18 Correct 64 ms 9932 KB Output is correct
19 Correct 62 ms 9964 KB Output is correct
20 Correct 62 ms 9836 KB Output is correct
21 Correct 114 ms 12052 KB Output is correct
22 Correct 6 ms 4988 KB Output is correct
23 Correct 108 ms 12104 KB Output is correct
24 Correct 114 ms 12076 KB Output is correct
25 Correct 111 ms 12140 KB Output is correct
26 Correct 103 ms 13556 KB Output is correct
27 Correct 102 ms 13548 KB Output is correct
28 Correct 104 ms 13552 KB Output is correct
29 Correct 105 ms 13500 KB Output is correct
30 Correct 129 ms 15084 KB Output is correct