Submission #197292

# Submission time Handle Problem Language Result Execution time Memory
197292 2020-01-20T08:17:32 Z dennisstar Snake Escaping (JOI18_snake_escaping) C++11
100 / 100
1042 ms 31572 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ryan bear
#define sq(X) ((X)*(X))
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int L, Q;
int a1[(1<<20)], a2[(1<<20)], a3[(1<<20)], a4[(1<<20)];
char s[20];

inline void f1() {
	int x, y, ans; x=y=ans=0;
	for (int i=0; i<L; i++) {
		if (s[i]=='1') x|=(1<<i);
		if (s[i]=='0') y|=(1<<i);
	}
	ans+=a3[x];
	for (int i=y; i; i=(i-1)&y) ans+=a3[i|x]*(a4[i]%2?-1:1);
	printf("%d\n", ans);
}
inline void f2() {
	int x, y, ans; x=y=ans=0;
	for (int i=0; i<L; i++) {
		if (s[i]=='0') x|=(1<<i);
		if (s[i]=='1') y|=(1<<i);
	}
	ans+=a2[x];
	for (int i=y; i; i=(i-1)&y) ans+=a2[i|x]*(a4[i]%2?-1:1);
	printf("%d\n", ans);
}
inline void f3() {
	int x, y, ans; x=y=ans=0;
	for (int i=0; i<L; i++) {
		if (s[i]=='1') x|=(1<<i);
		if (s[i]=='?') y|=(1<<i);
	}
	ans+=a1[x];
	for (int i=y; i; i=(i-1)&y) ans+=a1[i|x];
	printf("%d\n", ans);
}

int main() {
	scanf("%d %d", &L, &Q);
	for (int i=0; i<(1<<L); i++) scanf("%1d", &a1[i]);
	for (int i=0; i<(1<<L); i++) {
		if (i) a4[i]=a4[i-(i&-i)]+1;
		a2[i^((1<<L)-1)]+=a1[i];
		a3[i]+=a1[i];
	}
	for (int i=0; i<L; i++)
		for (int j=0; j<(1<<L); j++)
			if (!((j>>i)&1)) { a2[j]+=a2[j|(1<<i)]; a3[j]+=a3[j|(1<<i)]; }

	while (Q--) {
		scanf("%s", s);
		int c0=0, c1=0, cq=0;
		for (int i=0; i<L; i++) (s[i]=='0'?c0:s[i]=='1'?c1:cq)++;
		reverse(s, s+L);
		if (c0<=c1&&c0<=cq) f1();
		else if (c1<=c0&&c1<=cq) f2();
		else f3();
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &L, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~
snake_escaping.cpp:55:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=0; i<(1<<L); i++) scanf("%1d", &a1[i]);
                               ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 309 ms 10460 KB Output is correct
12 Correct 344 ms 10232 KB Output is correct
13 Correct 378 ms 9500 KB Output is correct
14 Correct 369 ms 9604 KB Output is correct
15 Correct 347 ms 10488 KB Output is correct
16 Correct 388 ms 9720 KB Output is correct
17 Correct 403 ms 9804 KB Output is correct
18 Correct 258 ms 11512 KB Output is correct
19 Correct 295 ms 8576 KB Output is correct
20 Correct 348 ms 10276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 309 ms 10460 KB Output is correct
12 Correct 344 ms 10232 KB Output is correct
13 Correct 378 ms 9500 KB Output is correct
14 Correct 369 ms 9604 KB Output is correct
15 Correct 347 ms 10488 KB Output is correct
16 Correct 388 ms 9720 KB Output is correct
17 Correct 403 ms 9804 KB Output is correct
18 Correct 258 ms 11512 KB Output is correct
19 Correct 295 ms 8576 KB Output is correct
20 Correct 348 ms 10276 KB Output is correct
21 Correct 410 ms 11408 KB Output is correct
22 Correct 426 ms 11520 KB Output is correct
23 Correct 472 ms 10676 KB Output is correct
24 Correct 462 ms 10320 KB Output is correct
25 Correct 416 ms 12228 KB Output is correct
26 Correct 496 ms 10896 KB Output is correct
27 Correct 497 ms 10744 KB Output is correct
28 Correct 279 ms 13148 KB Output is correct
29 Correct 404 ms 9048 KB Output is correct
30 Correct 432 ms 10728 KB Output is correct
31 Correct 467 ms 10468 KB Output is correct
32 Correct 465 ms 10624 KB Output is correct
33 Correct 437 ms 9448 KB Output is correct
34 Correct 488 ms 9676 KB Output is correct
35 Correct 498 ms 9996 KB Output is correct
36 Correct 276 ms 7288 KB Output is correct
37 Correct 406 ms 9304 KB Output is correct
38 Correct 415 ms 7264 KB Output is correct
39 Correct 477 ms 8592 KB Output is correct
40 Correct 467 ms 8276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 156 ms 19148 KB Output is correct
12 Correct 158 ms 19048 KB Output is correct
13 Correct 164 ms 18980 KB Output is correct
14 Correct 167 ms 18992 KB Output is correct
15 Correct 157 ms 19064 KB Output is correct
16 Correct 173 ms 18936 KB Output is correct
17 Correct 175 ms 19204 KB Output is correct
18 Correct 150 ms 19224 KB Output is correct
19 Correct 158 ms 18952 KB Output is correct
20 Correct 157 ms 18960 KB Output is correct
21 Correct 163 ms 19224 KB Output is correct
22 Correct 169 ms 19168 KB Output is correct
23 Correct 158 ms 18908 KB Output is correct
24 Correct 177 ms 19064 KB Output is correct
25 Correct 172 ms 18988 KB Output is correct
26 Correct 149 ms 18936 KB Output is correct
27 Correct 157 ms 19008 KB Output is correct
28 Correct 158 ms 18808 KB Output is correct
29 Correct 164 ms 19148 KB Output is correct
30 Correct 170 ms 18992 KB Output is correct
31 Correct 158 ms 18992 KB Output is correct
32 Correct 177 ms 18952 KB Output is correct
33 Correct 193 ms 18940 KB Output is correct
34 Correct 149 ms 19008 KB Output is correct
35 Correct 167 ms 19144 KB Output is correct
36 Correct 168 ms 19104 KB Output is correct
37 Correct 168 ms 19028 KB Output is correct
38 Correct 169 ms 19044 KB Output is correct
39 Correct 169 ms 19108 KB Output is correct
40 Correct 167 ms 19088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 309 ms 10460 KB Output is correct
12 Correct 344 ms 10232 KB Output is correct
13 Correct 378 ms 9500 KB Output is correct
14 Correct 369 ms 9604 KB Output is correct
15 Correct 347 ms 10488 KB Output is correct
16 Correct 388 ms 9720 KB Output is correct
17 Correct 403 ms 9804 KB Output is correct
18 Correct 258 ms 11512 KB Output is correct
19 Correct 295 ms 8576 KB Output is correct
20 Correct 348 ms 10276 KB Output is correct
21 Correct 410 ms 11408 KB Output is correct
22 Correct 426 ms 11520 KB Output is correct
23 Correct 472 ms 10676 KB Output is correct
24 Correct 462 ms 10320 KB Output is correct
25 Correct 416 ms 12228 KB Output is correct
26 Correct 496 ms 10896 KB Output is correct
27 Correct 497 ms 10744 KB Output is correct
28 Correct 279 ms 13148 KB Output is correct
29 Correct 404 ms 9048 KB Output is correct
30 Correct 432 ms 10728 KB Output is correct
31 Correct 467 ms 10468 KB Output is correct
32 Correct 465 ms 10624 KB Output is correct
33 Correct 437 ms 9448 KB Output is correct
34 Correct 488 ms 9676 KB Output is correct
35 Correct 498 ms 9996 KB Output is correct
36 Correct 276 ms 7288 KB Output is correct
37 Correct 406 ms 9304 KB Output is correct
38 Correct 415 ms 7264 KB Output is correct
39 Correct 477 ms 8592 KB Output is correct
40 Correct 467 ms 8276 KB Output is correct
41 Correct 156 ms 19148 KB Output is correct
42 Correct 158 ms 19048 KB Output is correct
43 Correct 164 ms 18980 KB Output is correct
44 Correct 167 ms 18992 KB Output is correct
45 Correct 157 ms 19064 KB Output is correct
46 Correct 173 ms 18936 KB Output is correct
47 Correct 175 ms 19204 KB Output is correct
48 Correct 150 ms 19224 KB Output is correct
49 Correct 158 ms 18952 KB Output is correct
50 Correct 157 ms 18960 KB Output is correct
51 Correct 163 ms 19224 KB Output is correct
52 Correct 169 ms 19168 KB Output is correct
53 Correct 158 ms 18908 KB Output is correct
54 Correct 177 ms 19064 KB Output is correct
55 Correct 172 ms 18988 KB Output is correct
56 Correct 149 ms 18936 KB Output is correct
57 Correct 157 ms 19008 KB Output is correct
58 Correct 158 ms 18808 KB Output is correct
59 Correct 164 ms 19148 KB Output is correct
60 Correct 170 ms 18992 KB Output is correct
61 Correct 158 ms 18992 KB Output is correct
62 Correct 177 ms 18952 KB Output is correct
63 Correct 193 ms 18940 KB Output is correct
64 Correct 149 ms 19008 KB Output is correct
65 Correct 167 ms 19144 KB Output is correct
66 Correct 168 ms 19104 KB Output is correct
67 Correct 168 ms 19028 KB Output is correct
68 Correct 169 ms 19044 KB Output is correct
69 Correct 169 ms 19108 KB Output is correct
70 Correct 167 ms 19088 KB Output is correct
71 Correct 709 ms 28636 KB Output is correct
72 Correct 681 ms 28636 KB Output is correct
73 Correct 764 ms 27104 KB Output is correct
74 Correct 850 ms 27384 KB Output is correct
75 Correct 638 ms 29560 KB Output is correct
76 Correct 991 ms 27768 KB Output is correct
77 Correct 978 ms 27580 KB Output is correct
78 Correct 479 ms 31572 KB Output is correct
79 Correct 646 ms 24676 KB Output is correct
80 Correct 681 ms 27788 KB Output is correct
81 Correct 761 ms 27640 KB Output is correct
82 Correct 830 ms 26276 KB Output is correct
83 Correct 644 ms 24616 KB Output is correct
84 Correct 1020 ms 25396 KB Output is correct
85 Correct 941 ms 25676 KB Output is correct
86 Correct 458 ms 23544 KB Output is correct
87 Correct 644 ms 25808 KB Output is correct
88 Correct 652 ms 22840 KB Output is correct
89 Correct 782 ms 24440 KB Output is correct
90 Correct 730 ms 24600 KB Output is correct
91 Correct 633 ms 23792 KB Output is correct
92 Correct 1042 ms 23896 KB Output is correct
93 Correct 965 ms 24164 KB Output is correct
94 Correct 449 ms 21560 KB Output is correct
95 Correct 873 ms 23884 KB Output is correct
96 Correct 864 ms 23352 KB Output is correct
97 Correct 875 ms 23444 KB Output is correct
98 Correct 866 ms 23296 KB Output is correct
99 Correct 895 ms 23376 KB Output is correct
100 Correct 929 ms 23544 KB Output is correct