Submission #940715

# Submission time Handle Problem Language Result Execution time Memory
940715 2024-03-07T13:58:06 Z phoenix0423 Plus Minus (BOI17_plusminus) C++17
12 / 100
1 ms 456 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
const int N = 1e9 + 7;

ll fpow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b & 1) ret = ret * a % N;
        a = a * a % N;
        b >>= 1;
    }
    return ret;
}

struct pt{
    int x, y, t;
    pt(int _x, int _y, int _t) : x(_x), y(_y), t(_t){}
};
bool compx(pt a, pt b){
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool compy(pt a, pt b){
    return a.y < b.y || (a.y == b.y && a.x < b.x);
}

signed main(void){
    fastio;
    int n, m, k;
    cin>>n>>m>>k;
    vector<pt> a;
    for(int i = 0; i < k; i++){
        int x, y;
        char t;
        cin>>t>>x>>y;
        a.pb(pt(x, y, (t == '-')));
    }
    if(n == 1 || m == 1){
        cout<<fpow(2, n + m - 1 - k)<<"\n";
        return 0;
    }
    sort(a.begin(), a.end(), compx);
    vector<int> fixed(2);
    map<int, int> st;
    for(int i = 1; i < k; i++){
        if(a[i].x == a[i - 1].x && a[i].y == a[i - 1].y + 1 && a[i].t == a[i - 1].t){
            fixed[0] = 1;
            if(st.find(a[i].y) != st.end()){
                if(((a[i].x & 1) ^ a[i].t) != st[a[i].y]){
                    cout<<0<<"\n";
                    return 0;
                }
            }
            st[a[i].y] = (a[i].x & 1) ^ a[i].t;
            if(st.find(a[i - 1].y) != st.end()){
                if(((a[i - 1].x & 1) ^ a[i - 1].t) != st[a[i - 1].y]){
                    cout<<0<<"\n";
                    return 0;
                }
            }
            st[a[i - 1].y] = (a[i - 1].x & 1) ^ a[i - 1].t;
        }
    }
    for(int i = 0; i < k; i++){
        if(st.find(a[i].y) != st.end()){
            if(((a[i].x & 1) ^ a[i].t) != st[a[i].y]){
                cout<<0<<"\n";
                return 0;
            }
        }    
    }
    st.clear();
    sort(a.begin(), a.end(), compy);
    for(int i = 1; i < k; i++){
        if(a[i].y == a[i - 1].y && a[i].x == a[i - 1].x + 1 && a[i].t == a[i - 1].t){
            if(fixed[0]){
                cout<<0<<"\n";
                return 0;
            }
            fixed[1] = 1;
            if(st.find(a[i].x) != st.end()){
                if(((a[i].y & 1) ^ a[i].t) != st[a[i].x]){
                    cout<<0<<"\n";
                    return 0;
                }
            }
            st[a[i].x] = (a[i].y & 1) ^ a[i].t;
            if(st.find(a[i - 1].x) != st.end()){
                if(((a[i - 1].y & 1) ^ a[i - 1].t) != st[a[i - 1].x]){
                    cout<<0<<"\n";
                    return 0;
                }
            }
            st[a[i - 1].x] = (a[i - 1].y & 1) ^ a[i - 1].t;
        }
    }
    for(int i = 0; i < k; i++){
        if(st.find(a[i].x) != st.end()){
            if(((a[i].y & 1) ^ a[i].t) != st[a[i].x]){
                cout<<0<<"\n";
                return 0;
            }
        }
    }
    set<int> fd[2];
    vector<int> bi(2, 1);
    for(int i = 0; i < k; i++){
        fd[0].insert(a[i].x), fd[1].insert(a[i].y);
        bi[((a[i].x + a[i].y) & 1)^ a[i].t] = 0;
    }
    if(fixed[0]){
        cout<<fpow(2, m - fd[1].size())<<"\n";
    }
    else if(fixed[1]){
        cout<<fpow(2, n - fd[0].size())<<"\n";
    }
    else{
        cout<<((fpow(2, m - fd[1].size()) + fpow(2, n - fd[0].size()) - bi[0] - bi[1] + N) % N)<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -