답안 #535727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535727 2022-03-11T03:44:35 Z sare Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 14452 KB
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
    stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
    string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
    string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
    return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
    bool fst = 1; string res = "{";
    for (const auto& x: v) {
        if (!fst) res += ", ";
        fst = 0; res += to_string(x);
    }
    res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
    return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
typedef long double ld;
#define all(x) (x).begin(), (x).end()

const int MAXN = 20, MAXQ = 1e6;
int l, q, dp[2][1 << MAXN];
string s;
 
int main() {
    cin >> l >> q >> s;
    for (int i = 0; i < (1 << l); i++) {
        dp[0][i] = dp[1][i] = s[i] - '0';
    }
    for (int k = 0; k < l; k++) {
        for (int i = 0; i < (1 << l); i++) {
            if (i >> k & 1) {
                dp[0][i] += dp[0][i ^ (1 << k)];
            }
            else {
                dp[1][i] += dp[1][i ^ (1 << k)];
            }
        }
    }
    while(q--) {
        int n[3] = {}, mask[3] = {};
        string t;
        cin >> t;
        for (int i = 0; i < l; i++) {
            if (t[i] == '?') {
                n[2]++;
                mask[2] ^= 1 << (l - i - 1);
            }
            else {
                n[t[i] - '0']++;
                mask[t[i] - '0'] ^= 1 << (l - i - 1);
            }
        }
        wis(n[0], n[1], n[2], mask[0], mask[1], mask[2]);
        ll ans = 0;
        if (n[2] <= min(n[0], n[1])) {
            for (int sub = mask[2]; sub; sub = (sub - 1) & mask[2]) {
                ans += s[sub | mask[1]] - '0';
            }
            ans += s[mask[1]] - '0';
        }
        else if (n[1] <= n[0]) {
            for (int sub = mask[1]; sub; sub = (sub - 1) & mask[1]) {
                ans += dp[0][sub ^ mask[1] ^ mask[2]] * (__builtin_popcount(sub) % 2 ? -1 : 1);
            } 
            ans += dp[0][mask[1] ^ mask[2]];
        }
        else {
            for (int sub = mask[0]; sub; sub = (sub - 1) & mask[0]) {
                ans += dp[1][((1 << l) - 1) ^ sub ^ mask[0] ^ mask[2]] * (__builtin_popcount(sub) % 2 ? -1 : 1);
            }
            ans += dp[1][((1 << l) - 1) ^ mask[0] ^ mask[2]];
        }
        cout << ans << '\n';
    }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:34:18: warning: statement has no effect [-Wunused-value]
   34 | #define wis(...) 0
      |                  ^
snake_escaping.cpp:73:9: note: in expansion of macro 'wis'
   73 |         wis(n[0], n[1], n[2], mask[0], mask[1], mask[2]);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1604 ms 4620 KB Output is correct
12 Correct 1611 ms 4304 KB Output is correct
13 Correct 1587 ms 3496 KB Output is correct
14 Correct 1572 ms 3620 KB Output is correct
15 Correct 1585 ms 4656 KB Output is correct
16 Correct 1586 ms 3836 KB Output is correct
17 Correct 1611 ms 3868 KB Output is correct
18 Correct 1558 ms 5632 KB Output is correct
19 Correct 1560 ms 2660 KB Output is correct
20 Correct 1623 ms 4300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1604 ms 4620 KB Output is correct
12 Correct 1611 ms 4304 KB Output is correct
13 Correct 1587 ms 3496 KB Output is correct
14 Correct 1572 ms 3620 KB Output is correct
15 Correct 1585 ms 4656 KB Output is correct
16 Correct 1586 ms 3836 KB Output is correct
17 Correct 1611 ms 3868 KB Output is correct
18 Correct 1558 ms 5632 KB Output is correct
19 Correct 1560 ms 2660 KB Output is correct
20 Correct 1623 ms 4300 KB Output is correct
21 Correct 1663 ms 4792 KB Output is correct
22 Correct 1686 ms 4816 KB Output is correct
23 Correct 1700 ms 3912 KB Output is correct
24 Correct 1671 ms 3712 KB Output is correct
25 Correct 1689 ms 5688 KB Output is correct
26 Correct 1721 ms 4144 KB Output is correct
27 Correct 1682 ms 4140 KB Output is correct
28 Correct 1607 ms 6824 KB Output is correct
29 Correct 1610 ms 2728 KB Output is correct
30 Correct 1659 ms 4872 KB Output is correct
31 Correct 1697 ms 4744 KB Output is correct
32 Correct 1779 ms 4696 KB Output is correct
33 Correct 1651 ms 3620 KB Output is correct
34 Correct 1736 ms 3692 KB Output is correct
35 Correct 1687 ms 4260 KB Output is correct
36 Correct 1641 ms 2804 KB Output is correct
37 Correct 1715 ms 4684 KB Output is correct
38 Correct 1667 ms 2704 KB Output is correct
39 Correct 1733 ms 3920 KB Output is correct
40 Correct 1737 ms 3768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 142 ms 9816 KB Output is correct
12 Correct 148 ms 9980 KB Output is correct
13 Correct 154 ms 9788 KB Output is correct
14 Correct 166 ms 9912 KB Output is correct
15 Correct 156 ms 9860 KB Output is correct
16 Correct 175 ms 9824 KB Output is correct
17 Correct 158 ms 9788 KB Output is correct
18 Correct 134 ms 9932 KB Output is correct
19 Correct 147 ms 9736 KB Output is correct
20 Correct 157 ms 9912 KB Output is correct
21 Correct 145 ms 9884 KB Output is correct
22 Correct 173 ms 9784 KB Output is correct
23 Correct 148 ms 9748 KB Output is correct
24 Correct 151 ms 9728 KB Output is correct
25 Correct 181 ms 9932 KB Output is correct
26 Correct 138 ms 9748 KB Output is correct
27 Correct 141 ms 9900 KB Output is correct
28 Correct 149 ms 9660 KB Output is correct
29 Correct 149 ms 9856 KB Output is correct
30 Correct 148 ms 9880 KB Output is correct
31 Correct 146 ms 9808 KB Output is correct
32 Correct 175 ms 10048 KB Output is correct
33 Correct 159 ms 9832 KB Output is correct
34 Correct 144 ms 9872 KB Output is correct
35 Correct 163 ms 9740 KB Output is correct
36 Correct 153 ms 9792 KB Output is correct
37 Correct 152 ms 9788 KB Output is correct
38 Correct 181 ms 9784 KB Output is correct
39 Correct 149 ms 9820 KB Output is correct
40 Correct 151 ms 9824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1604 ms 4620 KB Output is correct
12 Correct 1611 ms 4304 KB Output is correct
13 Correct 1587 ms 3496 KB Output is correct
14 Correct 1572 ms 3620 KB Output is correct
15 Correct 1585 ms 4656 KB Output is correct
16 Correct 1586 ms 3836 KB Output is correct
17 Correct 1611 ms 3868 KB Output is correct
18 Correct 1558 ms 5632 KB Output is correct
19 Correct 1560 ms 2660 KB Output is correct
20 Correct 1623 ms 4300 KB Output is correct
21 Correct 1663 ms 4792 KB Output is correct
22 Correct 1686 ms 4816 KB Output is correct
23 Correct 1700 ms 3912 KB Output is correct
24 Correct 1671 ms 3712 KB Output is correct
25 Correct 1689 ms 5688 KB Output is correct
26 Correct 1721 ms 4144 KB Output is correct
27 Correct 1682 ms 4140 KB Output is correct
28 Correct 1607 ms 6824 KB Output is correct
29 Correct 1610 ms 2728 KB Output is correct
30 Correct 1659 ms 4872 KB Output is correct
31 Correct 1697 ms 4744 KB Output is correct
32 Correct 1779 ms 4696 KB Output is correct
33 Correct 1651 ms 3620 KB Output is correct
34 Correct 1736 ms 3692 KB Output is correct
35 Correct 1687 ms 4260 KB Output is correct
36 Correct 1641 ms 2804 KB Output is correct
37 Correct 1715 ms 4684 KB Output is correct
38 Correct 1667 ms 2704 KB Output is correct
39 Correct 1733 ms 3920 KB Output is correct
40 Correct 1737 ms 3768 KB Output is correct
41 Correct 142 ms 9816 KB Output is correct
42 Correct 148 ms 9980 KB Output is correct
43 Correct 154 ms 9788 KB Output is correct
44 Correct 166 ms 9912 KB Output is correct
45 Correct 156 ms 9860 KB Output is correct
46 Correct 175 ms 9824 KB Output is correct
47 Correct 158 ms 9788 KB Output is correct
48 Correct 134 ms 9932 KB Output is correct
49 Correct 147 ms 9736 KB Output is correct
50 Correct 157 ms 9912 KB Output is correct
51 Correct 145 ms 9884 KB Output is correct
52 Correct 173 ms 9784 KB Output is correct
53 Correct 148 ms 9748 KB Output is correct
54 Correct 151 ms 9728 KB Output is correct
55 Correct 181 ms 9932 KB Output is correct
56 Correct 138 ms 9748 KB Output is correct
57 Correct 141 ms 9900 KB Output is correct
58 Correct 149 ms 9660 KB Output is correct
59 Correct 149 ms 9856 KB Output is correct
60 Correct 148 ms 9880 KB Output is correct
61 Correct 146 ms 9808 KB Output is correct
62 Correct 175 ms 10048 KB Output is correct
63 Correct 159 ms 9832 KB Output is correct
64 Correct 144 ms 9872 KB Output is correct
65 Correct 163 ms 9740 KB Output is correct
66 Correct 153 ms 9792 KB Output is correct
67 Correct 152 ms 9788 KB Output is correct
68 Correct 181 ms 9784 KB Output is correct
69 Correct 149 ms 9820 KB Output is correct
70 Correct 151 ms 9824 KB Output is correct
71 Execution timed out 2078 ms 14452 KB Time limit exceeded
72 Halted 0 ms 0 KB -