Submission #940693

# Submission time Handle Problem Language Result Execution time Memory
940693 2024-03-07T13:31:02 Z phoenix0423 Plus Minus (BOI17_plusminus) C++17
0 / 100
0 ms 344 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 == '-')));
    }
    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;
            }
            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];
    for(int i = 0; i < k; i++) fd[0].insert(a[i].x), fd[1].insert(a[i].y);
    // cout<<"ans : "<<n - fd[0].size()<<" "<<
    cout<<(fpow(2, n - fd[0].size()) * fpow(2, m - fd[1].size()) % N)<<"\n";
}

Compilation message

plusminus.cpp: In function 'int main()':
plusminus.cpp:53:42: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   53 |                 if((a[i].x & 1) ^ a[i].t != st[a[i].y]){
plusminus.cpp:60:50: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   60 |                 if((a[i - 1].x & 1) ^ a[i - 1].t != st[a[i - 1].y]){
plusminus.cpp:70:38: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   70 |             if((a[i].x & 1) ^ a[i].t != st[a[i].y]){
plusminus.cpp:85:42: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   85 |                 if((a[i].y & 1) ^ a[i].t != st[a[i].x]){
plusminus.cpp:92:50: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   92 |                 if((a[i - 1].y & 1) ^ a[i - 1].t != st[a[i - 1].x]){
plusminus.cpp:102:38: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
  102 |             if((a[i].y & 1) ^ a[i].t != st[a[i].x]){
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -