Submission #206639

# Submission time Handle Problem Language Result Execution time Memory
206639 2020-03-04T10:08:56 Z DodgeBallMan Plus Minus (BOI17_plusminus) C++14
100 / 100
152 ms 8296 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second

using namespace std;

const int mod = 1e9+7;
int n, m, k, valid;
long long ans;

long long cal( long long a, long long b ) {
    long long ret = 1, mul;
    for( ; b ; b >>= 1 ) {
        if( b & 1 ) ret = ( ret * a ) % mod;
        a = ( a * a ) % mod;
    }
    return ret;
}
void solve( int si, vector<int> &x, vector<int> &y, vector<int> &type ) {
    map<int,int> mp;
    for( int i = 0 ; i < x.size() ; i++ ) {
        int now = x[i], val = type[i];
        if( y[i] % 2 == 0 ) val ^= 1;
        if( !mp.count( now ) ) mp[now] = val;
        else if( mp[now] != val ) return ;
    }
    ans = ( ans + cal( 2, si - mp.size() ) ) % mod;
    int b = -1;
    for( pii p : mp ) {
        int now = ( ( p.x & 1 ) == p.y );
        if( b == -1 ) b = now;
        else if( b != now ) return;
    }
    ++valid;
}
vector<int> x, y, type;
int main()
{
    scanf("%d %d %d",&n,&m,&k);
    if( k == 0 ) return !printf("%lld\n",( cal( 2, n ) + cal( 2, m ) - 2 + mod ) % mod );
    for( int i = 1 ; i <= k ; i++ ) {
        int a, b;
        char c;
        scanf(" %c %d %d",&c,&a,&b);
        x.emplace_back( a ), y.emplace_back( b ), type.emplace_back( c == '+' );
    }
    solve( n, x, y, type ), solve( m, y, x, type );
    if( valid == 2 ) ans = ( ans - 1 + mod ) % mod;
    printf("%lld",ans);
    return 0;
}

Compilation message

plusminus.cpp: In function 'long long int cal(long long int, long long int)':
plusminus.cpp:13:24: warning: unused variable 'mul' [-Wunused-variable]
     long long ret = 1, mul;
                        ^~~
plusminus.cpp: In function 'void solve(int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
plusminus.cpp:22:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for( int i = 0 ; i < x.size() ; i++ ) {
                      ~~^~~~~~~~~~
plusminus.cpp: In function 'int main()':
plusminus.cpp:40: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:45: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 time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 35 ms 2536 KB Output is correct
17 Correct 36 ms 2536 KB Output is correct
18 Correct 36 ms 2680 KB Output is correct
19 Correct 62 ms 2664 KB Output is correct
20 Correct 69 ms 2536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 35 ms 2536 KB Output is correct
17 Correct 36 ms 2536 KB Output is correct
18 Correct 36 ms 2680 KB Output is correct
19 Correct 62 ms 2664 KB Output is correct
20 Correct 69 ms 2536 KB Output is correct
21 Correct 119 ms 5604 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 40 ms 2916 KB Output is correct
24 Correct 41 ms 2920 KB Output is correct
25 Correct 40 ms 2916 KB Output is correct
26 Correct 78 ms 5864 KB Output is correct
27 Correct 76 ms 5480 KB Output is correct
28 Correct 99 ms 6120 KB Output is correct
29 Correct 124 ms 7012 KB Output is correct
30 Correct 152 ms 8296 KB Output is correct