답안 #208827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208827 2020-03-12T09:04:38 Z Siberian Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
2000 ms 5496 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

int n, q;
string s;

void read() {
	cin >> n >> q;
	cin >> s;
	for (int i = 0; i < (1 << n); i++)
		s[i] = s[i] - '0';
}

pair<int, int> get_mask() {
	string s;
	cin >> s;
	int mask = 0;
	int must = 0;
	for (int i = 0; i < n; i++) {
		mask *= 2;
		if (s[i] != '0') mask++;
		must *= 2;
		if (s[i] == '1') must++;
	}
	return {mask, must};
}

void build() {

}

bool check_submask(int mask, int submask) {
	return (mask & submask) == submask;
}

void solve() {
	auto x = get_mask();
	int mask = x.first, must = x.second;
	int ans = 0;
	//cout << "mask = " << mask << endl;
	for (int i = mask; i >= 0; i = (i - 1) & mask) {
		if (check_submask(i, must)) ans += s[i];
		if (i == 0) break;
	}
	cout << ans << "\n";
}

void run() {
	build();
	while (q--) {
		solve();
	}
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 1714 ms 4548 KB Output is correct
12 Correct 338 ms 3960 KB Output is correct
13 Correct 322 ms 3364 KB Output is correct
14 Correct 385 ms 3316 KB Output is correct
15 Correct 774 ms 4472 KB Output is correct
16 Correct 479 ms 3532 KB Output is correct
17 Correct 535 ms 3448 KB Output is correct
18 Correct 1554 ms 5496 KB Output is correct
19 Correct 294 ms 2424 KB Output is correct
20 Correct 1677 ms 4320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 1714 ms 4548 KB Output is correct
12 Correct 338 ms 3960 KB Output is correct
13 Correct 322 ms 3364 KB Output is correct
14 Correct 385 ms 3316 KB Output is correct
15 Correct 774 ms 4472 KB Output is correct
16 Correct 479 ms 3532 KB Output is correct
17 Correct 535 ms 3448 KB Output is correct
18 Correct 1554 ms 5496 KB Output is correct
19 Correct 294 ms 2424 KB Output is correct
20 Correct 1677 ms 4320 KB Output is correct
21 Execution timed out 2090 ms 1276 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Execution timed out 2081 ms 2452 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 1714 ms 4548 KB Output is correct
12 Correct 338 ms 3960 KB Output is correct
13 Correct 322 ms 3364 KB Output is correct
14 Correct 385 ms 3316 KB Output is correct
15 Correct 774 ms 4472 KB Output is correct
16 Correct 479 ms 3532 KB Output is correct
17 Correct 535 ms 3448 KB Output is correct
18 Correct 1554 ms 5496 KB Output is correct
19 Correct 294 ms 2424 KB Output is correct
20 Correct 1677 ms 4320 KB Output is correct
21 Execution timed out 2090 ms 1276 KB Time limit exceeded
22 Halted 0 ms 0 KB -