제출 #129622

#제출 시각아이디문제언어결과실행 시간메모리
129622SamAndPlus Minus (BOI17_plusminus)C++17
54 / 100
1072 ms17356 KiB
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007, N = 1003;

int ast(int x, int n)
{
    if (n < 0)
        return 0;
    if (n == 0)
        return 1;
    if (n % 2 == 0)
    {
        int y = ast(x, n / 2);
        return (y * 1LL * y) % M;
    }
    else
    {
        int y = ast(x, n - 1);
        return (x * 1LL * y) % M;
    }
}

int ans0, ans1;

int n, m, k;

map<int, vector<int> >  sp0, sm0;
set<int> z1, z2;
set<int> sp, sm;

int main()
{
    //freopen("input.txt", "r", stdin);
    //ios_base::sync_with_stdio(false);
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 0; i < k; ++i)
    {
        char ty;
        int x, y;
        scanf(" %c%d%d", &ty, &x, &y);
        if (ty == '-')
            sm0[x].push_back(y);
        else
            sp0[x].push_back(y);
        if (x % 2 == 1)
        {
            if (ty == '+')
                sp.insert(y);
            else
                sm.insert(y);
        }
        else
        {
            if (ty == '-')
                sp.insert(y);
            else
                sm.insert(y);
        }
    }

    // count ans0
    ans0 = 1;
    for (map<int, vector<int> >::iterator it = sp0.begin(); it != sp0.end(); ++it)
    {
        for (int i = 0; i < it->second.size(); ++i)
        {
            if (it->second[i] % 2 == 0)
                z1.insert(it->first);
            else
                z2.insert(it->first);
        }
    }
    for (map<int, vector<int> >::iterator it = sm0.begin(); it != sm0.end(); ++it)
    {
        for (int i = 0; i < it->second.size(); ++i)
        {
            if (it->second[i] % 2 == 1)
                z1.insert(it->first);
            else
                z2.insert(it->first);
        }
    }
    for (set<int>::iterator it = z1.begin(); it != z1.end(); ++it)
    {
        if (z2.find((*it)) != z2.end())
        {
            ans0 = 0;
            break;
        }
    }
    ans0 = (ans0 * 1LL * ast(2, n - z1.size() - z2.size()));
    //count ans1
    for (int y = 1; y <= m; ++y)
    {
        if (sm.find(y) != sm.end() && sp.find(y) != sp.end())
        {
            cout << ans0 << endl;
            return 0;
        }
    }
    ans1 = ast(2, m - sm.size() - sp.size());
    bool zz1 = true, zz2 = true;
    for (set<int>::iterator it = sm.begin(); it != sm.end(); ++it)
    {
        if ((*it) % 2 == 1)
            zz1 = false;
        else
            zz2 = false;
    }
    for (set<int>::iterator it = sp.begin(); it != sp.end(); ++it)
    {
        if ((*it) % 2 == 0)
            zz1 = false;
        else
            zz2 = false;
    }
    if (zz1)
        --ans1;
    if (zz2)
        --ans1;
    ans1 += M;
    ans1 %= M;
    cout << (ans0 + ans1) % M << endl;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

plusminus.cpp: In function 'int main()':
plusminus.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < it->second.size(); ++i)
                         ~~^~~~~~~~~~~~~~~~~~~
plusminus.cpp:75:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < it->second.size(); ++i)
                         ~~^~~~~~~~~~~~~~~~~~~
plusminus.cpp:35: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:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d%d", &ty, &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...