답안 #135225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135225 2019-07-23T20:50:56 Z duality Snake Escaping (JOI18_snake_escaping) C++11
100 / 100
1072 ms 23632 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

char S[(1 << 20)+1],T[21];
int sum0[1 << 20],sum1[1 << 20],bits[1 << 20];
int main() {
    int i,j;
    int L,Q;
    scanf("%d %d %s",&L,&Q,S);
    for (i = 0; i < (1 << L); i++) sum0[i] = sum1[i] = S[i]-'0';
    for (i = 0; i < L; i++) {
        for (j = 0; j < (1 << L); j++) {
            if (j & (1 << i)) sum0[j] += sum0[j^(1 << i)];
            else sum1[j] += sum1[j^(1 << i)];
        }
    }
    for (i = 0; i < (1 << L); i++) {
        for (j = 0; j < L; j++) {
            if (i & (1 << j)) bits[i]++;
        }
    }
    for (i = 0; i < Q; i++) {
        scanf("%s",T);
        reverse(T,T+L);
        int a = 0,b = 0,c = 0,ca = 0,cb = 0,cc = 0;
        for (j = 0; j < L; j++) {
            if (T[j] == '0') a |= (1 << j),ca++;
            else if (T[j] == '1') b |= (1 << j),cb++;
            else c |= (1 << j),cc++;
        }
        int ans = 0;
        if ((ca <= cb) && (ca <= cc)) {
            for (j = a; j > 0; j = (j-1) & a) {
                if (bits[j] & 1) ans -= sum1[j | b];
                else ans += sum1[j | b];
            }
            ans += sum1[b];
        }
        else if ((cb <= ca) && (cb <= cc)) {
            for (j = b; j > 0; j = (j-1) & b) {
                if (bits[j] & 1) ans -= sum0[(b^j) | c];
                else ans += sum0[(b^j) | c];
            }
            ans += sum0[b | c];
        }
        else {
            for (j = c; j > 0; j = (j-1) & c) ans += S[j | b]-'0';
            ans += S[b]-'0';
        }
        printf("%d\n",ans);
    }

    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %s",&L,&Q,S);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",T);
         ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 264 ms 15068 KB Output is correct
12 Correct 273 ms 14800 KB Output is correct
13 Correct 313 ms 14072 KB Output is correct
14 Correct 306 ms 13944 KB Output is correct
15 Correct 285 ms 15064 KB Output is correct
16 Correct 312 ms 14200 KB Output is correct
17 Correct 335 ms 14200 KB Output is correct
18 Correct 224 ms 15992 KB Output is correct
19 Correct 254 ms 13048 KB Output is correct
20 Correct 281 ms 14704 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 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 264 ms 15068 KB Output is correct
12 Correct 273 ms 14800 KB Output is correct
13 Correct 313 ms 14072 KB Output is correct
14 Correct 306 ms 13944 KB Output is correct
15 Correct 285 ms 15064 KB Output is correct
16 Correct 312 ms 14200 KB Output is correct
17 Correct 335 ms 14200 KB Output is correct
18 Correct 224 ms 15992 KB Output is correct
19 Correct 254 ms 13048 KB Output is correct
20 Correct 281 ms 14704 KB Output is correct
21 Correct 341 ms 15156 KB Output is correct
22 Correct 332 ms 15256 KB Output is correct
23 Correct 400 ms 14576 KB Output is correct
24 Correct 430 ms 14712 KB Output is correct
25 Correct 366 ms 17176 KB Output is correct
26 Correct 425 ms 15628 KB Output is correct
27 Correct 414 ms 15616 KB Output is correct
28 Correct 284 ms 18172 KB Output is correct
29 Correct 344 ms 13896 KB Output is correct
30 Correct 368 ms 15680 KB Output is correct
31 Correct 387 ms 15204 KB Output is correct
32 Correct 413 ms 14884 KB Output is correct
33 Correct 371 ms 13456 KB Output is correct
34 Correct 410 ms 13284 KB Output is correct
35 Correct 415 ms 13472 KB Output is correct
36 Correct 256 ms 11940 KB Output is correct
37 Correct 333 ms 13820 KB Output is correct
38 Correct 345 ms 11344 KB Output is correct
39 Correct 379 ms 12416 KB Output is correct
40 Correct 410 ms 12120 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 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 187 ms 16000 KB Output is correct
12 Correct 142 ms 15992 KB Output is correct
13 Correct 153 ms 15992 KB Output is correct
14 Correct 157 ms 15864 KB Output is correct
15 Correct 142 ms 15996 KB Output is correct
16 Correct 171 ms 15868 KB Output is correct
17 Correct 159 ms 15904 KB Output is correct
18 Correct 147 ms 16084 KB Output is correct
19 Correct 150 ms 15740 KB Output is correct
20 Correct 147 ms 15924 KB Output is correct
21 Correct 163 ms 16044 KB Output is correct
22 Correct 167 ms 15852 KB Output is correct
23 Correct 152 ms 15792 KB Output is correct
24 Correct 169 ms 15824 KB Output is correct
25 Correct 156 ms 16040 KB Output is correct
26 Correct 137 ms 15764 KB Output is correct
27 Correct 160 ms 16000 KB Output is correct
28 Correct 146 ms 15896 KB Output is correct
29 Correct 157 ms 15864 KB Output is correct
30 Correct 153 ms 16008 KB Output is correct
31 Correct 154 ms 15892 KB Output is correct
32 Correct 161 ms 15912 KB Output is correct
33 Correct 154 ms 16048 KB Output is correct
34 Correct 133 ms 15756 KB Output is correct
35 Correct 173 ms 15860 KB Output is correct
36 Correct 150 ms 15992 KB Output is correct
37 Correct 161 ms 16096 KB Output is correct
38 Correct 160 ms 16092 KB Output is correct
39 Correct 159 ms 15852 KB Output is correct
40 Correct 155 ms 15868 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 376 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 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 264 ms 15068 KB Output is correct
12 Correct 273 ms 14800 KB Output is correct
13 Correct 313 ms 14072 KB Output is correct
14 Correct 306 ms 13944 KB Output is correct
15 Correct 285 ms 15064 KB Output is correct
16 Correct 312 ms 14200 KB Output is correct
17 Correct 335 ms 14200 KB Output is correct
18 Correct 224 ms 15992 KB Output is correct
19 Correct 254 ms 13048 KB Output is correct
20 Correct 281 ms 14704 KB Output is correct
21 Correct 341 ms 15156 KB Output is correct
22 Correct 332 ms 15256 KB Output is correct
23 Correct 400 ms 14576 KB Output is correct
24 Correct 430 ms 14712 KB Output is correct
25 Correct 366 ms 17176 KB Output is correct
26 Correct 425 ms 15628 KB Output is correct
27 Correct 414 ms 15616 KB Output is correct
28 Correct 284 ms 18172 KB Output is correct
29 Correct 344 ms 13896 KB Output is correct
30 Correct 368 ms 15680 KB Output is correct
31 Correct 387 ms 15204 KB Output is correct
32 Correct 413 ms 14884 KB Output is correct
33 Correct 371 ms 13456 KB Output is correct
34 Correct 410 ms 13284 KB Output is correct
35 Correct 415 ms 13472 KB Output is correct
36 Correct 256 ms 11940 KB Output is correct
37 Correct 333 ms 13820 KB Output is correct
38 Correct 345 ms 11344 KB Output is correct
39 Correct 379 ms 12416 KB Output is correct
40 Correct 410 ms 12120 KB Output is correct
41 Correct 187 ms 16000 KB Output is correct
42 Correct 142 ms 15992 KB Output is correct
43 Correct 153 ms 15992 KB Output is correct
44 Correct 157 ms 15864 KB Output is correct
45 Correct 142 ms 15996 KB Output is correct
46 Correct 171 ms 15868 KB Output is correct
47 Correct 159 ms 15904 KB Output is correct
48 Correct 147 ms 16084 KB Output is correct
49 Correct 150 ms 15740 KB Output is correct
50 Correct 147 ms 15924 KB Output is correct
51 Correct 163 ms 16044 KB Output is correct
52 Correct 167 ms 15852 KB Output is correct
53 Correct 152 ms 15792 KB Output is correct
54 Correct 169 ms 15824 KB Output is correct
55 Correct 156 ms 16040 KB Output is correct
56 Correct 137 ms 15764 KB Output is correct
57 Correct 160 ms 16000 KB Output is correct
58 Correct 146 ms 15896 KB Output is correct
59 Correct 157 ms 15864 KB Output is correct
60 Correct 153 ms 16008 KB Output is correct
61 Correct 154 ms 15892 KB Output is correct
62 Correct 161 ms 15912 KB Output is correct
63 Correct 154 ms 16048 KB Output is correct
64 Correct 133 ms 15756 KB Output is correct
65 Correct 173 ms 15860 KB Output is correct
66 Correct 150 ms 15992 KB Output is correct
67 Correct 161 ms 16096 KB Output is correct
68 Correct 160 ms 16092 KB Output is correct
69 Correct 159 ms 15852 KB Output is correct
70 Correct 155 ms 15868 KB Output is correct
71 Correct 582 ms 19760 KB Output is correct
72 Correct 613 ms 20984 KB Output is correct
73 Correct 706 ms 19508 KB Output is correct
74 Correct 830 ms 19604 KB Output is correct
75 Correct 550 ms 21624 KB Output is correct
76 Correct 829 ms 20108 KB Output is correct
77 Correct 854 ms 19896 KB Output is correct
78 Correct 440 ms 23632 KB Output is correct
79 Correct 523 ms 17784 KB Output is correct
80 Correct 576 ms 20760 KB Output is correct
81 Correct 677 ms 20728 KB Output is correct
82 Correct 827 ms 19664 KB Output is correct
83 Correct 546 ms 18800 KB Output is correct
84 Correct 874 ms 19776 KB Output is correct
85 Correct 781 ms 19948 KB Output is correct
86 Correct 422 ms 17564 KB Output is correct
87 Correct 598 ms 20780 KB Output is correct
88 Correct 539 ms 17656 KB Output is correct
89 Correct 638 ms 19168 KB Output is correct
90 Correct 671 ms 19440 KB Output is correct
91 Correct 566 ms 18668 KB Output is correct
92 Correct 1072 ms 19784 KB Output is correct
93 Correct 770 ms 19664 KB Output is correct
94 Correct 399 ms 17412 KB Output is correct
95 Correct 714 ms 19428 KB Output is correct
96 Correct 735 ms 19480 KB Output is correct
97 Correct 746 ms 19464 KB Output is correct
98 Correct 757 ms 19392 KB Output is correct
99 Correct 713 ms 19336 KB Output is correct
100 Correct 695 ms 19304 KB Output is correct