답안 #1113395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113395 2024-11-16T14:05:21 Z vjudge1 Snake Escaping (JOI18_snake_escaping) C++17
58 / 100
2000 ms 39684 KB
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define INF 1000000000
#define fi first
#define se second
//#define cin fin
//#define cout fout
using namespace std;
double const EPS = 1e-14;
typedef long long ll;
const ll P = 10007;
const ll mod = 1e9 + 7;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
const int M = 2097152;
ll dp1[M], dp0[M];
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int n, m; cin >> n >> m;
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++) {
            dp1[i] = s[i]-'0'; dp0[i] = s[i]-'0';  }
    //int mx = 0;
    for(int j = 1; j < 21; j++) {
        for(int i = 0; i < M; i++) {
            if(((1<<(j-1))&i) > 0) {
                dp1[i] += dp1[(i^(1<<(j-1)))];
               // mx = max((i^(1<<(j-1))),mx);
            }
            else {
                dp0[i] += dp0[(i^(1<<(j-1)))];
               // mx = max((i^(1<<(j-1))),mx);
            }
        }
    }
   // cout << mx << 'p' << endl;
    while(m--) {
        string cur; cin >> cur;
        int cnt0 = 0, cnt1 = 0, cnt = 0;
        for(int i = 0; i < cur.size(); i++) {
            if(cur[i] == '0') cnt0++;
            else if(cur[i] == '1') cnt1++;
            else cnt++;
        }
        ll ans = 0;
        int siz = cur.size(); siz--;
        if(cnt <= 6) {
            for(int i = 0; i < (1<<cnt); i++) {
                int indx = 0;
                ll sum = 0;
                for(int j = cur.size()-1; j >= 0; j--) {
                    if(cur[j] == '1') sum += (1<<(siz-j));
                    else if(cur[j] == '?' && (i&(1<<(indx++))) > 0) sum += (1<<(siz-j));
                }
              //  cout << sum << 'a' << endl;
                ans += s[sum]-'0';
            }
        }
        else if(cnt1 <= 6) {

            for(int i = 0; i < (1<<cnt1); i++) {
                int indx = 0;
                ll sum = 0;
                int cn = 0;
                for(int j = cur.size()-1; j >= 0; j--) {
                    if(cur[j] == '?') {
                        sum += (1<<(siz-j));
                    }
                    else if(cur[j] == '1') {
                        if((i&(1<<(indx++))) > 0) sum += (1<<(siz-j));
                        else cn++;
                    }
                }
             //   cout << cn << ' ' << sum << ' ' << i << 'a' << endl;
                if(cn%2 == 0) ans += dp1[sum];
                else ans -= dp1[sum];
            }

        }
        else {
            for(int i = 0; i < (1<<cnt0); i++) {
                int indx = 0;
                ll sum = 0;
                int cn = 0;
                for(int j = cur.size()-1; j >= 0; j--) {
                    if(cur[j] == '1') {
                        sum += (1<<(siz-j));
                    }
                    else if(cur[j] == '0' && (i&(1<<(indx++))) > 0) {
                        sum += (1<<(siz-j));
                        cn++;
                    }
                }
             //   cout << cn << ' ' << sum << ' ' << i << 'a' << dp0[sum] << endl;
                if(cn%2 == 0) ans += dp0[sum];
                else ans -= dp0[sum];
            }

        }
        cout << ans << endl;
    }
    return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < s.size(); i++) {
      |                    ~~^~~~~~~~~~
snake_escaping.cpp:45:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for(int i = 0; i < cur.size(); i++) {
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33104 KB Output is correct
2 Correct 63 ms 33104 KB Output is correct
3 Correct 58 ms 33104 KB Output is correct
4 Correct 65 ms 33096 KB Output is correct
5 Correct 71 ms 33104 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 66 ms 33104 KB Output is correct
8 Correct 62 ms 33172 KB Output is correct
9 Correct 62 ms 33104 KB Output is correct
10 Correct 66 ms 33096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33104 KB Output is correct
2 Correct 63 ms 33104 KB Output is correct
3 Correct 58 ms 33104 KB Output is correct
4 Correct 65 ms 33096 KB Output is correct
5 Correct 71 ms 33104 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 66 ms 33104 KB Output is correct
8 Correct 62 ms 33172 KB Output is correct
9 Correct 62 ms 33104 KB Output is correct
10 Correct 66 ms 33096 KB Output is correct
11 Correct 1884 ms 39684 KB Output is correct
12 Correct 1618 ms 36856 KB Output is correct
13 Correct 701 ms 37592 KB Output is correct
14 Correct 714 ms 36168 KB Output is correct
15 Execution timed out 2063 ms 35400 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33104 KB Output is correct
2 Correct 63 ms 33104 KB Output is correct
3 Correct 58 ms 33104 KB Output is correct
4 Correct 65 ms 33096 KB Output is correct
5 Correct 71 ms 33104 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 66 ms 33104 KB Output is correct
8 Correct 62 ms 33172 KB Output is correct
9 Correct 62 ms 33104 KB Output is correct
10 Correct 66 ms 33096 KB Output is correct
11 Correct 1884 ms 39684 KB Output is correct
12 Correct 1618 ms 36856 KB Output is correct
13 Correct 701 ms 37592 KB Output is correct
14 Correct 714 ms 36168 KB Output is correct
15 Execution timed out 2063 ms 35400 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33104 KB Output is correct
2 Correct 63 ms 33104 KB Output is correct
3 Correct 58 ms 33104 KB Output is correct
4 Correct 65 ms 33096 KB Output is correct
5 Correct 71 ms 33104 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 66 ms 33104 KB Output is correct
8 Correct 62 ms 33172 KB Output is correct
9 Correct 62 ms 33104 KB Output is correct
10 Correct 66 ms 33096 KB Output is correct
11 Correct 80 ms 37352 KB Output is correct
12 Correct 93 ms 36984 KB Output is correct
13 Correct 168 ms 37352 KB Output is correct
14 Correct 256 ms 36584 KB Output is correct
15 Correct 126 ms 36836 KB Output is correct
16 Correct 247 ms 37096 KB Output is correct
17 Correct 214 ms 37096 KB Output is correct
18 Correct 67 ms 37352 KB Output is correct
19 Correct 87 ms 36584 KB Output is correct
20 Correct 103 ms 37300 KB Output is correct
21 Correct 167 ms 37392 KB Output is correct
22 Correct 285 ms 37096 KB Output is correct
23 Correct 144 ms 37356 KB Output is correct
24 Correct 283 ms 37608 KB Output is correct
25 Correct 211 ms 36396 KB Output is correct
26 Correct 88 ms 37364 KB Output is correct
27 Correct 82 ms 37604 KB Output is correct
28 Correct 78 ms 37356 KB Output is correct
29 Correct 175 ms 36072 KB Output is correct
30 Correct 285 ms 36724 KB Output is correct
31 Correct 119 ms 37488 KB Output is correct
32 Correct 228 ms 37620 KB Output is correct
33 Correct 185 ms 37164 KB Output is correct
34 Correct 65 ms 36836 KB Output is correct
35 Correct 153 ms 36684 KB Output is correct
36 Correct 152 ms 36840 KB Output is correct
37 Correct 150 ms 37608 KB Output is correct
38 Correct 170 ms 36932 KB Output is correct
39 Correct 154 ms 37276 KB Output is correct
40 Correct 174 ms 37620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33104 KB Output is correct
2 Correct 63 ms 33104 KB Output is correct
3 Correct 58 ms 33104 KB Output is correct
4 Correct 65 ms 33096 KB Output is correct
5 Correct 71 ms 33104 KB Output is correct
6 Correct 61 ms 33104 KB Output is correct
7 Correct 66 ms 33104 KB Output is correct
8 Correct 62 ms 33172 KB Output is correct
9 Correct 62 ms 33104 KB Output is correct
10 Correct 66 ms 33096 KB Output is correct
11 Correct 1884 ms 39684 KB Output is correct
12 Correct 1618 ms 36856 KB Output is correct
13 Correct 701 ms 37592 KB Output is correct
14 Correct 714 ms 36168 KB Output is correct
15 Execution timed out 2063 ms 35400 KB Time limit exceeded
16 Halted 0 ms 0 KB -