답안 #129626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
129626 2019-07-12T19:43:23 Z SamAnd Plus Minus (BOI17_plusminus) C++17
100 / 100
283 ms 22856 KB
#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 (set<int>::iterator it = sm.begin(); it != sm.end(); ++it)
    {
        if (sp.find((*it)) != 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;
}

Compilation message

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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 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 380 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 62 ms 1244 KB Output is correct
17 Correct 62 ms 1272 KB Output is correct
18 Correct 65 ms 1400 KB Output is correct
19 Correct 57 ms 1144 KB Output is correct
20 Correct 61 ms 1180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 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 380 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 62 ms 1244 KB Output is correct
17 Correct 62 ms 1272 KB Output is correct
18 Correct 65 ms 1400 KB Output is correct
19 Correct 57 ms 1144 KB Output is correct
20 Correct 61 ms 1180 KB Output is correct
21 Correct 236 ms 14456 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 239 ms 15924 KB Output is correct
24 Correct 205 ms 15864 KB Output is correct
25 Correct 206 ms 15792 KB Output is correct
26 Correct 212 ms 17420 KB Output is correct
27 Correct 206 ms 19128 KB Output is correct
28 Correct 216 ms 19064 KB Output is correct
29 Correct 230 ms 19076 KB Output is correct
30 Correct 283 ms 22856 KB Output is correct