답안 #66922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66922 2018-08-12T19:16:23 Z ekrem Snake Escaping (JOI18_snake_escaping) C++
12 / 100
2000 ms 32316 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[N], prec[N], cvp[N], kaps[3000][200];
char c;
pair < int , int > q[N];
void hesapla(int);


// bas bitinin ikilik bitde 7 uzunlugunda ? isaretsiz oldugunu varsay bit 13 uzun.
int f(int bas, int bit){
	if(dp[bit] != -1)
		return dp[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[bit] = a[sorg];
	}
	return dp[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);
}

bool kapsar(int uc, int iki){
	// cout << uc << " " << iki << endl;
	if(kaps[uc][iki] != -1)
		return kaps[uc][iki];
	int yuc = uc;
	int yiki = iki;
	for(int i = 1; i <= 7; i++){
		if(yuc%3 != 2 and yiki%2 != yuc%3)
			return kaps[uc][iki] = 0;
		yuc /= 3;
		yiki /= 3;
	}
	return kaps[uc][iki] = 1;
}

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);
	memset(kaps, -1, sizeof kaps);
	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;
		q[i] = mp(bit, son);
		// printf("%d\n",bul(bit, son));
	}

	for(int i = 0; i < 2187 ; i++)
		for(int j = 1; j < (1<<7); j++)
			kapsar(i, j);

	for(int i = 0; i < (1<<7); i++){
		memset(dp, -1, sizeof dp);
		for(int j = 1; j <= m; j++)
			if(kapsar(q[j].st, i)){
				// cout << i << " - > " << q[j].nd << endl;
				cvp[j] += bul(i, q[j].nd);
			}
	}
	for(int i = 1; i <= m; i++)
		printf("%d\n",cvp[i]);
	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 'bool kapsar(int, int)':
snake_escaping.cpp:46:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    return kaps[uc][iki] = 0;
           ~~~~~~~~~~~~~~^~~
snake_escaping.cpp:50:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  return kaps[uc][iki] = 1;
         ~~~~~~~~~~~~~~^~~
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:66:16: warning: unused variable 'say' [-Wunused-variable]
   int bit = 0, say = 0, son = 0, crp = 1;
                ^~~
snake_escaping.cpp:60: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:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
   ~~~~~^~~~~~~~~~
snake_escaping.cpp:68: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 83 ms 15352 KB Output is correct
2 Correct 87 ms 15352 KB Output is correct
3 Correct 82 ms 15408 KB Output is correct
4 Correct 78 ms 15436 KB Output is correct
5 Correct 86 ms 15436 KB Output is correct
6 Correct 91 ms 15436 KB Output is correct
7 Correct 87 ms 15576 KB Output is correct
8 Correct 80 ms 15576 KB Output is correct
9 Correct 83 ms 15576 KB Output is correct
10 Correct 83 ms 15580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15352 KB Output is correct
2 Correct 87 ms 15352 KB Output is correct
3 Correct 82 ms 15408 KB Output is correct
4 Correct 78 ms 15436 KB Output is correct
5 Correct 86 ms 15436 KB Output is correct
6 Correct 91 ms 15436 KB Output is correct
7 Correct 87 ms 15576 KB Output is correct
8 Correct 80 ms 15576 KB Output is correct
9 Correct 83 ms 15576 KB Output is correct
10 Correct 83 ms 15580 KB Output is correct
11 Correct 1532 ms 31252 KB Output is correct
12 Correct 1581 ms 31252 KB Output is correct
13 Correct 1358 ms 31252 KB Output is correct
14 Correct 1423 ms 31252 KB Output is correct
15 Correct 1545 ms 31292 KB Output is correct
16 Correct 1669 ms 31292 KB Output is correct
17 Correct 1727 ms 31292 KB Output is correct
18 Correct 1485 ms 32316 KB Output is correct
19 Correct 1341 ms 32316 KB Output is correct
20 Correct 1605 ms 32316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15352 KB Output is correct
2 Correct 87 ms 15352 KB Output is correct
3 Correct 82 ms 15408 KB Output is correct
4 Correct 78 ms 15436 KB Output is correct
5 Correct 86 ms 15436 KB Output is correct
6 Correct 91 ms 15436 KB Output is correct
7 Correct 87 ms 15576 KB Output is correct
8 Correct 80 ms 15576 KB Output is correct
9 Correct 83 ms 15576 KB Output is correct
10 Correct 83 ms 15580 KB Output is correct
11 Correct 1532 ms 31252 KB Output is correct
12 Correct 1581 ms 31252 KB Output is correct
13 Correct 1358 ms 31252 KB Output is correct
14 Correct 1423 ms 31252 KB Output is correct
15 Correct 1545 ms 31292 KB Output is correct
16 Correct 1669 ms 31292 KB Output is correct
17 Correct 1727 ms 31292 KB Output is correct
18 Correct 1485 ms 32316 KB Output is correct
19 Correct 1341 ms 32316 KB Output is correct
20 Correct 1605 ms 32316 KB Output is correct
21 Correct 1632 ms 32316 KB Output is correct
22 Correct 1641 ms 32316 KB Output is correct
23 Execution timed out 2076 ms 32316 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15352 KB Output is correct
2 Correct 87 ms 15352 KB Output is correct
3 Correct 82 ms 15408 KB Output is correct
4 Correct 78 ms 15436 KB Output is correct
5 Correct 86 ms 15436 KB Output is correct
6 Correct 91 ms 15436 KB Output is correct
7 Correct 87 ms 15576 KB Output is correct
8 Correct 80 ms 15576 KB Output is correct
9 Correct 83 ms 15576 KB Output is correct
10 Correct 83 ms 15580 KB Output is correct
11 Incorrect 237 ms 32316 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 15352 KB Output is correct
2 Correct 87 ms 15352 KB Output is correct
3 Correct 82 ms 15408 KB Output is correct
4 Correct 78 ms 15436 KB Output is correct
5 Correct 86 ms 15436 KB Output is correct
6 Correct 91 ms 15436 KB Output is correct
7 Correct 87 ms 15576 KB Output is correct
8 Correct 80 ms 15576 KB Output is correct
9 Correct 83 ms 15576 KB Output is correct
10 Correct 83 ms 15580 KB Output is correct
11 Correct 1532 ms 31252 KB Output is correct
12 Correct 1581 ms 31252 KB Output is correct
13 Correct 1358 ms 31252 KB Output is correct
14 Correct 1423 ms 31252 KB Output is correct
15 Correct 1545 ms 31292 KB Output is correct
16 Correct 1669 ms 31292 KB Output is correct
17 Correct 1727 ms 31292 KB Output is correct
18 Correct 1485 ms 32316 KB Output is correct
19 Correct 1341 ms 32316 KB Output is correct
20 Correct 1605 ms 32316 KB Output is correct
21 Correct 1632 ms 32316 KB Output is correct
22 Correct 1641 ms 32316 KB Output is correct
23 Execution timed out 2076 ms 32316 KB Time limit exceeded
24 Halted 0 ms 0 KB -