답안 #66909

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

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

void hesapla(int);


// bas bitinin ikilik bitde 7 uzunlugunda ? isaretsiz oldugunu varsay bit 13 uzun.
int f(int bas, int bit){
	if(dp[bas][bit] != -1)
		return dp[bas][bit];
	int x = prec[bit];
	if(x <= 0){
		x = -x;
		// cout << x << endl;
		int sorg = bas*(1<<13) + x;
		// cout << sorg<< " -> " << a[sorg] << endl;
		return dp[bas][bit] = a[sorg];
	}
	return dp[bas][bit] = f(bas, bit - x) + f(bas, bit - x - x);
}

//bu sefer bas'da soru isareti olabilir.
int bul(int bas, int son){
	int x = prec[bas];
	if(x <= 0)
		return f(-prec[bas] , son);
	return bul(bas - x, son) + bul(bas - x - x, son);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	for(int i = 0; i < N; i++)
		hesapla(i);
	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, say = 0, son = 0, crp = 1;
		for(int i = 1; i <= n; i++){
			scanf(" %c" ,&c);
			bit *= 3;
			bit += (c == '?') ? 2 : c - '0';
		}
		// cout << bit << endl;
		for(int say = 1; say <= 13; say++){
			son += crp*(bit%3);
			crp *= 3;
			bit/=3;
		}
		// cout << bit << " -> " << son << endl;
		printf("%d\n",bul(bit, son));
	}
	return 0;
}


void hesapla(int bit){
	int yed = bit, crp = 1, ckr = -1;
	while(yed){
		if(yed%3 == 2){
			ckr = crp;
			break;
		}
		crp *= 3;
		yed /= 3;
	}
	prec[bit] = ckr;
	if(ckr == -1){
		yed = bit;
		int say = 0, cvp = 0;
		while(yed){
			cvp += (1<<say)*(yed%3);
			say++;
			yed /= 3;
		}
		prec[bit] = -cvp;
	}
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:50:16: warning: unused variable 'say' [-Wunused-variable]
   int bit = 0, say = 0, son = 0, crp = 1;
                ^~~
snake_escaping.cpp:44: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:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
   ~~~~~^~~~~~~~~~
snake_escaping.cpp:52:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c" ,&c);
    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 393 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 393 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 393 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 393 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 393 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -