답안 #66868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66868 2018-08-12T16:49:44 Z ekrem Snake Escaping (JOI18_snake_escaping) C++
12 / 100
978 ms 14316 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, a[N], dp[N];
char c;

int f(int bit){
	if(dp[bit] != -1)
		return dp[bit];
	int yed = bit, crp = 1, ckr = -1;
	while(yed){
		if(yed%3 == 2){
			ckr = crp;
			break;
		}
		crp *= 3;
		yed /= 3;
	}
	if(ckr == -1){
		yed = bit;
		int say = 0, cvp = 0;
		while(yed){
			cvp += (1<<say)*(yed%3);
			say++;
			yed /= 3;
		}
		return dp[bit] = a[cvp];
	}
	return dp[bit] = f(bit - ckr) + f(bit - ckr - ckr);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	memset(dp, -1, sizeof dp);
	scanf("%d %d",&n ,&m);
	for(int i = 0; i < (1<<n); i++){
		scanf(" %c",&c);
		a[i] = c - '0';
	}
	for(int i = 1; i <= m; i++){
		int bit = 0;
		for(int i = 1; i <= n; i++){
			scanf(" %c" ,&c);
			bit *= 3;
			bit += (c == '?') ? 2 : c - '0';
		}
		printf("%d\n",f(bit));
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n ,&m);
  ~~~~~^~~~~~~~~~~~~~~~
snake_escaping.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
   ~~~~~^~~~~~~~~~
snake_escaping.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c" ,&c);
    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 8 ms 4532 KB Output is correct
4 Correct 8 ms 4532 KB Output is correct
5 Correct 8 ms 4532 KB Output is correct
6 Correct 7 ms 4592 KB Output is correct
7 Correct 8 ms 4592 KB Output is correct
8 Correct 9 ms 4592 KB Output is correct
9 Correct 8 ms 4592 KB Output is correct
10 Correct 8 ms 4592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 8 ms 4532 KB Output is correct
4 Correct 8 ms 4532 KB Output is correct
5 Correct 8 ms 4532 KB Output is correct
6 Correct 7 ms 4592 KB Output is correct
7 Correct 8 ms 4592 KB Output is correct
8 Correct 9 ms 4592 KB Output is correct
9 Correct 8 ms 4592 KB Output is correct
10 Correct 8 ms 4592 KB Output is correct
11 Correct 909 ms 11892 KB Output is correct
12 Correct 796 ms 11892 KB Output is correct
13 Correct 862 ms 11892 KB Output is correct
14 Correct 763 ms 12312 KB Output is correct
15 Correct 750 ms 13260 KB Output is correct
16 Correct 928 ms 13260 KB Output is correct
17 Correct 943 ms 13260 KB Output is correct
18 Correct 949 ms 14316 KB Output is correct
19 Correct 754 ms 14316 KB Output is correct
20 Correct 825 ms 14316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 8 ms 4532 KB Output is correct
4 Correct 8 ms 4532 KB Output is correct
5 Correct 8 ms 4532 KB Output is correct
6 Correct 7 ms 4592 KB Output is correct
7 Correct 8 ms 4592 KB Output is correct
8 Correct 9 ms 4592 KB Output is correct
9 Correct 8 ms 4592 KB Output is correct
10 Correct 8 ms 4592 KB Output is correct
11 Correct 909 ms 11892 KB Output is correct
12 Correct 796 ms 11892 KB Output is correct
13 Correct 862 ms 11892 KB Output is correct
14 Correct 763 ms 12312 KB Output is correct
15 Correct 750 ms 13260 KB Output is correct
16 Correct 928 ms 13260 KB Output is correct
17 Correct 943 ms 13260 KB Output is correct
18 Correct 949 ms 14316 KB Output is correct
19 Correct 754 ms 14316 KB Output is correct
20 Correct 825 ms 14316 KB Output is correct
21 Incorrect 978 ms 14316 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 8 ms 4532 KB Output is correct
4 Correct 8 ms 4532 KB Output is correct
5 Correct 8 ms 4532 KB Output is correct
6 Correct 7 ms 4592 KB Output is correct
7 Correct 8 ms 4592 KB Output is correct
8 Correct 9 ms 4592 KB Output is correct
9 Correct 8 ms 4592 KB Output is correct
10 Correct 8 ms 4592 KB Output is correct
11 Incorrect 69 ms 14316 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4216 KB Output is correct
2 Correct 8 ms 4456 KB Output is correct
3 Correct 8 ms 4532 KB Output is correct
4 Correct 8 ms 4532 KB Output is correct
5 Correct 8 ms 4532 KB Output is correct
6 Correct 7 ms 4592 KB Output is correct
7 Correct 8 ms 4592 KB Output is correct
8 Correct 9 ms 4592 KB Output is correct
9 Correct 8 ms 4592 KB Output is correct
10 Correct 8 ms 4592 KB Output is correct
11 Correct 909 ms 11892 KB Output is correct
12 Correct 796 ms 11892 KB Output is correct
13 Correct 862 ms 11892 KB Output is correct
14 Correct 763 ms 12312 KB Output is correct
15 Correct 750 ms 13260 KB Output is correct
16 Correct 928 ms 13260 KB Output is correct
17 Correct 943 ms 13260 KB Output is correct
18 Correct 949 ms 14316 KB Output is correct
19 Correct 754 ms 14316 KB Output is correct
20 Correct 825 ms 14316 KB Output is correct
21 Incorrect 978 ms 14316 KB Output isn't correct
22 Halted 0 ms 0 KB -