답안 #197291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197291 2020-01-20T08:15:38 Z dennisstar Snake Escaping (JOI18_snake_escaping) C++11
100 / 100
1091 ms 46120 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];
pii stk[(1<<20)];
vim bs;

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<=L/3) f1();
		else if (c1<=L/3) f2();
		else f3();
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:56: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:57: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:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 307 ms 6604 KB Output is correct
12 Correct 338 ms 6292 KB Output is correct
13 Correct 330 ms 5584 KB Output is correct
14 Correct 318 ms 5676 KB Output is correct
15 Correct 318 ms 6492 KB Output is correct
16 Correct 343 ms 5752 KB Output is correct
17 Correct 371 ms 5712 KB Output is correct
18 Correct 262 ms 7636 KB Output is correct
19 Correct 286 ms 4536 KB Output is correct
20 Correct 317 ms 6256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 307 ms 6604 KB Output is correct
12 Correct 338 ms 6292 KB Output is correct
13 Correct 330 ms 5584 KB Output is correct
14 Correct 318 ms 5676 KB Output is correct
15 Correct 318 ms 6492 KB Output is correct
16 Correct 343 ms 5752 KB Output is correct
17 Correct 371 ms 5712 KB Output is correct
18 Correct 262 ms 7636 KB Output is correct
19 Correct 286 ms 4536 KB Output is correct
20 Correct 317 ms 6256 KB Output is correct
21 Correct 360 ms 6712 KB Output is correct
22 Correct 429 ms 7032 KB Output is correct
23 Correct 451 ms 5924 KB Output is correct
24 Correct 439 ms 5880 KB Output is correct
25 Correct 390 ms 7800 KB Output is correct
26 Correct 450 ms 6264 KB Output is correct
27 Correct 474 ms 6124 KB Output is correct
28 Correct 289 ms 8688 KB Output is correct
29 Correct 411 ms 4676 KB Output is correct
30 Correct 375 ms 6780 KB Output is correct
31 Correct 434 ms 6484 KB Output is correct
32 Correct 444 ms 6520 KB Output is correct
33 Correct 408 ms 5372 KB Output is correct
34 Correct 456 ms 5624 KB Output is correct
35 Correct 464 ms 6096 KB Output is correct
36 Correct 274 ms 2928 KB Output is correct
37 Correct 410 ms 4856 KB Output is correct
38 Correct 431 ms 2936 KB Output is correct
39 Correct 439 ms 3960 KB Output is correct
40 Correct 433 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 160 ms 18952 KB Output is correct
12 Correct 163 ms 18900 KB Output is correct
13 Correct 166 ms 18808 KB Output is correct
14 Correct 171 ms 18832 KB Output is correct
15 Correct 160 ms 18940 KB Output is correct
16 Correct 171 ms 18936 KB Output is correct
17 Correct 174 ms 18868 KB Output is correct
18 Correct 151 ms 19128 KB Output is correct
19 Correct 161 ms 18808 KB Output is correct
20 Correct 168 ms 18908 KB Output is correct
21 Correct 165 ms 18872 KB Output is correct
22 Correct 170 ms 18936 KB Output is correct
23 Correct 162 ms 18984 KB Output is correct
24 Correct 184 ms 18936 KB Output is correct
25 Correct 180 ms 18808 KB Output is correct
26 Correct 152 ms 18808 KB Output is correct
27 Correct 160 ms 18936 KB Output is correct
28 Correct 163 ms 18684 KB Output is correct
29 Correct 182 ms 18808 KB Output is correct
30 Correct 168 ms 18936 KB Output is correct
31 Correct 160 ms 18824 KB Output is correct
32 Correct 180 ms 18964 KB Output is correct
33 Correct 171 ms 19064 KB Output is correct
34 Correct 150 ms 18936 KB Output is correct
35 Correct 173 ms 19056 KB Output is correct
36 Correct 172 ms 19068 KB Output is correct
37 Correct 172 ms 18992 KB Output is correct
38 Correct 172 ms 19048 KB Output is correct
39 Correct 170 ms 18944 KB Output is correct
40 Correct 173 ms 19068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 424 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 307 ms 6604 KB Output is correct
12 Correct 338 ms 6292 KB Output is correct
13 Correct 330 ms 5584 KB Output is correct
14 Correct 318 ms 5676 KB Output is correct
15 Correct 318 ms 6492 KB Output is correct
16 Correct 343 ms 5752 KB Output is correct
17 Correct 371 ms 5712 KB Output is correct
18 Correct 262 ms 7636 KB Output is correct
19 Correct 286 ms 4536 KB Output is correct
20 Correct 317 ms 6256 KB Output is correct
21 Correct 360 ms 6712 KB Output is correct
22 Correct 429 ms 7032 KB Output is correct
23 Correct 451 ms 5924 KB Output is correct
24 Correct 439 ms 5880 KB Output is correct
25 Correct 390 ms 7800 KB Output is correct
26 Correct 450 ms 6264 KB Output is correct
27 Correct 474 ms 6124 KB Output is correct
28 Correct 289 ms 8688 KB Output is correct
29 Correct 411 ms 4676 KB Output is correct
30 Correct 375 ms 6780 KB Output is correct
31 Correct 434 ms 6484 KB Output is correct
32 Correct 444 ms 6520 KB Output is correct
33 Correct 408 ms 5372 KB Output is correct
34 Correct 456 ms 5624 KB Output is correct
35 Correct 464 ms 6096 KB Output is correct
36 Correct 274 ms 2928 KB Output is correct
37 Correct 410 ms 4856 KB Output is correct
38 Correct 431 ms 2936 KB Output is correct
39 Correct 439 ms 3960 KB Output is correct
40 Correct 433 ms 3960 KB Output is correct
41 Correct 160 ms 18952 KB Output is correct
42 Correct 163 ms 18900 KB Output is correct
43 Correct 166 ms 18808 KB Output is correct
44 Correct 171 ms 18832 KB Output is correct
45 Correct 160 ms 18940 KB Output is correct
46 Correct 171 ms 18936 KB Output is correct
47 Correct 174 ms 18868 KB Output is correct
48 Correct 151 ms 19128 KB Output is correct
49 Correct 161 ms 18808 KB Output is correct
50 Correct 168 ms 18908 KB Output is correct
51 Correct 165 ms 18872 KB Output is correct
52 Correct 170 ms 18936 KB Output is correct
53 Correct 162 ms 18984 KB Output is correct
54 Correct 184 ms 18936 KB Output is correct
55 Correct 180 ms 18808 KB Output is correct
56 Correct 152 ms 18808 KB Output is correct
57 Correct 160 ms 18936 KB Output is correct
58 Correct 163 ms 18684 KB Output is correct
59 Correct 182 ms 18808 KB Output is correct
60 Correct 168 ms 18936 KB Output is correct
61 Correct 160 ms 18824 KB Output is correct
62 Correct 180 ms 18964 KB Output is correct
63 Correct 171 ms 19064 KB Output is correct
64 Correct 150 ms 18936 KB Output is correct
65 Correct 173 ms 19056 KB Output is correct
66 Correct 172 ms 19068 KB Output is correct
67 Correct 172 ms 18992 KB Output is correct
68 Correct 172 ms 19048 KB Output is correct
69 Correct 170 ms 18944 KB Output is correct
70 Correct 173 ms 19068 KB Output is correct
71 Correct 693 ms 43324 KB Output is correct
72 Correct 698 ms 43384 KB Output is correct
73 Correct 783 ms 41968 KB Output is correct
74 Correct 843 ms 42424 KB Output is correct
75 Correct 647 ms 44408 KB Output is correct
76 Correct 862 ms 42872 KB Output is correct
77 Correct 999 ms 42708 KB Output is correct
78 Correct 482 ms 46120 KB Output is correct
79 Correct 645 ms 40568 KB Output is correct
80 Correct 674 ms 43640 KB Output is correct
81 Correct 767 ms 43384 KB Output is correct
82 Correct 926 ms 41856 KB Output is correct
83 Correct 667 ms 41680 KB Output is correct
84 Correct 1091 ms 42536 KB Output is correct
85 Correct 983 ms 42700 KB Output is correct
86 Correct 467 ms 40108 KB Output is correct
87 Correct 652 ms 43344 KB Output is correct
88 Correct 688 ms 40312 KB Output is correct
89 Correct 780 ms 42104 KB Output is correct
90 Correct 804 ms 42520 KB Output is correct
91 Correct 654 ms 41208 KB Output is correct
92 Correct 1069 ms 42748 KB Output is correct
93 Correct 1014 ms 42616 KB Output is correct
94 Correct 458 ms 40508 KB Output is correct
95 Correct 896 ms 42744 KB Output is correct
96 Correct 883 ms 42424 KB Output is correct
97 Correct 903 ms 42600 KB Output is correct
98 Correct 877 ms 42608 KB Output is correct
99 Correct 898 ms 42540 KB Output is correct
100 Correct 900 ms 42204 KB Output is correct