Submission #148106

# Submission time Handle Problem Language Result Execution time Memory
148106 2019-08-31T13:56:27 Z WhipppedCream Plus Minus (BOI17_plusminus) C++17
100 / 100
164 ms 13080 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector< pair<int, int> >
typedef long long ll;
using namespace std;
struct node
{
    int typ, x, y;
    node(){}
    node(int a, int b, int c)
    {
        typ = a;
        x = b;
        y = c;
    }
    bool operator < (node other) const
    {
        if(y != other.y) return y< other.y;
        return x< other.x;
    }
};
const int md = 1e9 + 7;
int add(int a, int b)
{
    return (a+b)%md;
}
int sub(int a, int b)
{
    return (a-b+md)%md;
}
int mul(int a, int b)
{
    return (1LL*a*b)%md;
}
int power(int a, int b)
{
    if(b == 0) return 1;
    int x = power(a, b/2);
    int y = mul(x, x);
    if(b%2) y = mul(y, a);
    return y;
}
vector<node> foo;
map<int, int> longfix;
int main()
{
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 0; i< k; i++)
    {
        char t; int x, y;
        scanf(" %c %d %d", &t, &x, &y);
        foo.pb(node(t, x, y));
    }
    sort(foo.begin(), foo.end());
    int ans = 0;
    //Check for case 1: all are alternating
    //Condition: No connected component in each column.
    bool ok = 1;
    map<int, int> mag;
    if(foo.empty())
    {
        ans = add(ans, power(2, m));
        ans = add(ans, power(2, n));
        ans = sub(ans, 2);
        printf("%d\n", ans);
        return 0;
    }
    else
    {
        for(int i = 0; i< (int) foo.size(); i++)
        {
            int k = (foo[i].typ == '+')?1:-1;
            int x = foo[i].x, y = foo[i].y;
            if(x%2 == 0) k = -k;
            if(mag.find(y) == mag.end()) mag[y] = k;
            else if(mag[y] != k)
            {
                ok = 0;
                break;
            }
        }
        int fix = mag.size();
        assert(fix<= m);
        if(ok) ans = add(ans, power(2, m-fix));
    }
    int ok2 = 1;
    for(int i = 0; i< (int) foo.size(); i++)
    {
        int k = (foo[i].typ == '+')?1:-1;
        int x = foo[i].x; int y = foo[i].y;
        if(y%2 == 0) k = -k;
        if(longfix.find(x) == longfix.end()) longfix[x] = k;
        else if(longfix[x] != k)
        {
            ok2 = 0;
            break;
        }
    }
    int fix = longfix.size();
    assert(fix<= n);
    if(ok2) ans = add(ans, power(2, n-fix));
    if(ok && ok2)
    {
        bool good1 = 1, good2 = 1;
        for(auto x : longfix)
        {
            if((x.first%2 == 1 && x.second == -1) || (x.first%2 == 0 && x.second == 1)) good1 = 0;
            if((x.first%2 == 1 && x.second == 1) || (x.first%2 == 0 && x.second == -1)) good2 = 0;
        }
        for(auto x : mag)
        {
            if((x.first%2 == 1 && x.second == -1) || (x.first%2 == 0 && x.second == 1)) good1 = 0;
            if((x.first%2 == 1 && x.second == 1) || (x.first%2 == 0 && x.second == -1)) good2 = 0;
        }
        if(good1) ans = sub(ans, 1);
        if(good2) ans = sub(ans, 1);
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

plusminus.cpp: In function 'int main()':
plusminus.cpp:53: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:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c %d %d", &t, &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 41 ms 2800 KB Output is correct
17 Correct 40 ms 2800 KB Output is correct
18 Correct 41 ms 2800 KB Output is correct
19 Correct 58 ms 2800 KB Output is correct
20 Correct 61 ms 2800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 41 ms 2800 KB Output is correct
17 Correct 40 ms 2800 KB Output is correct
18 Correct 41 ms 2800 KB Output is correct
19 Correct 58 ms 2800 KB Output is correct
20 Correct 61 ms 2800 KB Output is correct
21 Correct 128 ms 8524 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 44 ms 3212 KB Output is correct
24 Correct 44 ms 3056 KB Output is correct
25 Correct 44 ms 3184 KB Output is correct
26 Correct 88 ms 7916 KB Output is correct
27 Correct 87 ms 7272 KB Output is correct
28 Correct 106 ms 9324 KB Output is correct
29 Correct 148 ms 10856 KB Output is correct
30 Correct 164 ms 13080 KB Output is correct