답안 #476492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476492 2021-09-27T11:10:14 Z keta_tsimakuridze Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
695 ms 65540 KB
#include<bits/stdc++.h>
#define f first
#define s second
////#define int long long
#define pii pair<int,int>
using namespace std;
const int N = 1048576 + 5, mod = 1e9 + 7; // !
int t,dp1[N][22],dp2[N][22],L,q;
vector<int> cnt[4];
main(){
			ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
            cin >> L >> q;
            string s;
            cin >> s;
            for(int i = 0; i < (1 << L); i++) { 
                        dp1[i][0] = s[i] - '0';
                        for(int j = 0; j < L; j++) {
                                    if(j) dp1[i][j] = dp1[i][j - 1];
                                    if((1 << j) & i) dp1[i][j] += dp1[i ^ (1 << j)][j];
                        }
            }
            for(int i = (1 << L) - 1; i >= 0; i--) {
                        dp2[i][0] = s[i] - '0';
                        for(int j = 0; j < L; j++) {
                                    if(j) dp2[i][j] = dp2[i][j - 1];
                                    if(!((1 << j) & i)) dp2[i][j] += dp2[i ^ (1 << j)][j];
                        }
            }
            while(q--) {
                        string t;
                        cin >> t;
                        int x = 0;
                        reverse(t.begin(),t.end());
                        int c = 0, a = 0, b = 0;
                        for(int i = 0; i < 3; i++) cnt[i].clear();
                        for(int i = 0; i < t.size(); i++) {
                                    if(t[i] == '0') cnt[0].push_back(i), a += 1 << i;
                                    else if(t[i] == '1') cnt[1].push_back(i),b += 1 << i;
                                    else cnt[2].push_back(i),c += 1 << i;
                        }
                        long long ans = 0;
                        if(cnt[2].size() < 7) {
                        		
                                    for(int i = c;; i = (i - 1) & c) {
                                                ans += s[i | b] - '0';
                                                if(!i) break;
                                    }
                        }
                        else if(cnt[1].size() < 7) {	
                                    int p = __builtin_popcount(b) % 2;
                                    for(int i = b;; i = (i - 1) & b) {
                                            ans += (__builtin_popcount(i) % 2 == p ? 1 : -1)
                                                    * dp1[i | c][L - 1];
                                            if(!i) break;
                                                    
                                    }
                        }
                        else {
                                    for(int i = a;; i = (i - 1) & a) {
                                            ans += (__builtin_popcount(i) % 2 == 0 ? 1 : -1)
                                                       * dp2[i | b][L - 1];
                                            if(!i) break;    
                                    }
                        }
                        cout << ans << "\n";
            }
 }

Compilation message

snake_escaping.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:36:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |                         for(int i = 0; i < t.size(); i++) {
      |                                        ~~^~~~~~~~~~
snake_escaping.cpp:32:29: warning: unused variable 'x' [-Wunused-variable]
   32 |                         int x = 0;
      |                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 289 ms 4600 KB Output is correct
12 Correct 308 ms 4100 KB Output is correct
13 Correct 289 ms 3420 KB Output is correct
14 Correct 301 ms 3524 KB Output is correct
15 Correct 348 ms 4592 KB Output is correct
16 Correct 308 ms 3620 KB Output is correct
17 Correct 324 ms 3696 KB Output is correct
18 Correct 219 ms 5448 KB Output is correct
19 Correct 267 ms 2556 KB Output is correct
20 Correct 337 ms 4196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 289 ms 4600 KB Output is correct
12 Correct 308 ms 4100 KB Output is correct
13 Correct 289 ms 3420 KB Output is correct
14 Correct 301 ms 3524 KB Output is correct
15 Correct 348 ms 4592 KB Output is correct
16 Correct 308 ms 3620 KB Output is correct
17 Correct 324 ms 3696 KB Output is correct
18 Correct 219 ms 5448 KB Output is correct
19 Correct 267 ms 2556 KB Output is correct
20 Correct 337 ms 4196 KB Output is correct
21 Correct 695 ms 5840 KB Output is correct
22 Correct 355 ms 5836 KB Output is correct
23 Correct 343 ms 4828 KB Output is correct
24 Correct 329 ms 4676 KB Output is correct
25 Correct 355 ms 6852 KB Output is correct
26 Correct 362 ms 5168 KB Output is correct
27 Correct 378 ms 5220 KB Output is correct
28 Correct 230 ms 7748 KB Output is correct
29 Correct 277 ms 3696 KB Output is correct
30 Correct 428 ms 5916 KB Output is correct
31 Correct 400 ms 5744 KB Output is correct
32 Correct 346 ms 5768 KB Output is correct
33 Correct 313 ms 4548 KB Output is correct
34 Correct 346 ms 4868 KB Output is correct
35 Correct 372 ms 5140 KB Output is correct
36 Correct 203 ms 3756 KB Output is correct
37 Correct 371 ms 5800 KB Output is correct
38 Correct 295 ms 3696 KB Output is correct
39 Correct 338 ms 4940 KB Output is correct
40 Correct 323 ms 4760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Runtime error 84 ms 65540 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 289 ms 4600 KB Output is correct
12 Correct 308 ms 4100 KB Output is correct
13 Correct 289 ms 3420 KB Output is correct
14 Correct 301 ms 3524 KB Output is correct
15 Correct 348 ms 4592 KB Output is correct
16 Correct 308 ms 3620 KB Output is correct
17 Correct 324 ms 3696 KB Output is correct
18 Correct 219 ms 5448 KB Output is correct
19 Correct 267 ms 2556 KB Output is correct
20 Correct 337 ms 4196 KB Output is correct
21 Correct 695 ms 5840 KB Output is correct
22 Correct 355 ms 5836 KB Output is correct
23 Correct 343 ms 4828 KB Output is correct
24 Correct 329 ms 4676 KB Output is correct
25 Correct 355 ms 6852 KB Output is correct
26 Correct 362 ms 5168 KB Output is correct
27 Correct 378 ms 5220 KB Output is correct
28 Correct 230 ms 7748 KB Output is correct
29 Correct 277 ms 3696 KB Output is correct
30 Correct 428 ms 5916 KB Output is correct
31 Correct 400 ms 5744 KB Output is correct
32 Correct 346 ms 5768 KB Output is correct
33 Correct 313 ms 4548 KB Output is correct
34 Correct 346 ms 4868 KB Output is correct
35 Correct 372 ms 5140 KB Output is correct
36 Correct 203 ms 3756 KB Output is correct
37 Correct 371 ms 5800 KB Output is correct
38 Correct 295 ms 3696 KB Output is correct
39 Correct 338 ms 4940 KB Output is correct
40 Correct 323 ms 4760 KB Output is correct
41 Runtime error 84 ms 65540 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -