Submission #823430

# Submission time Handle Problem Language Result Execution time Memory
823430 2023-08-12T14:03:47 Z serifefedartar Plus Minus (BOI17_plusminus) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 2005

map<int,int> row_repet, col_repet;
ll binExp(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}

int main() {
    fast
    ll N, M, K;
    cin >> N >> M >> K;

    bool rowCheck = true, colCheck = true;
    for (int i = 0; i < K; i++) {
        char ch; int row, col;
        cin >> ch >> row >> col;
            
        int rowRepType, colRepType;
        if (ch == '+') {
            if (col % 2)
                rowRepType = 1;
            else
                rowRepType = 2;

            if (row % 2)
                colRepType = 1;
            else
                rowRepType = 2;
        } else {
            if (col % 2)
                rowRepType = 2;
            else
                rowRepType = 1;

            if (row % 2)
                colRepType = 2;
            else
                rowRepType = 1;
        }

        if (row_repet[row] != 0 && row_repet[row] != rowRepType)
            rowCheck = false;
        else
            row_repet[row] = rowRepType;

        if (col_repet[col] != 0 && col_repet[col] != colRepType)
            colCheck = false;
        else
            col_repet[col] = colRepType;
    }

    ll ans = 0;
    if (rowCheck)
        ans = (ans + binExp(2, N - row_repet.size())) % MOD;

    if (colCheck)
        ans = (ans + binExp(2, M - col_repet.size())) % MOD;

    if (rowCheck && colCheck) {
        bool firstCase = true, secondCase = true;
        for (auto u : row_repet) {
            if (u.f % 2 == u.s % 2)
                secondCase = false;
            else
                firstCase = false;
        }
        for (auto u : col_repet) {
            if (u.f % 2 == u.s % 2)
                secondCase = false;
            else
                firstCase = false;   
        }
        ans = ans - firstCase - secondCase;
    }

    while (ans < 0)
        ans += MOD;
    cout << ans << "\n";
}

Compilation message

plusminus.cpp: In function 'int main()':
plusminus.cpp:65:28: warning: 'colRepType' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |             col_repet[col] = colRepType;
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -