답안 #66946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66946 2018-08-12T20:17:23 Z ekrem Snake Escaping (JOI18_snake_escaping) C++
12 / 100
1208 ms 26552 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[2000002];
void hesapla(int);

// 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);

	memset(kaps, -1, sizeof kaps);

	for(int i = 0; i < 1594323; i++){
		int x = i, crp = 1, ckr = -1, say = 0, bit = 0;
		while(x){
			if(x%3 == 2){
				ckr = crp;
				break;
			}
			bit += (1<<say)*(x%3);
			say++;
			crp *= 3;
			x /= 3;
		}
		if(ckr == -1)
			prec[i] = -bit;
		else
			prec[i] = ckr;
	}

	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 = 0; j < (1<<7); j++){
	// 		int yuc = i;
	// 		int yiki = j;
	// 		bool f = 1;
	// 		for(int i = 1; i <= 7; i++){
	// 			if(yuc%3 != 2 and yiki%2 != yuc%3){
	// 				f = kaps[i][j] = 0;
	// 				break;
	// 			}
	// 			yuc /= 3;
	// 			yiki /= 3;
	// 		}
	// 		if(f)
	// 			return kaps[i][j] = 1;
	// 	}
	for(int i = 0; i < 2187; i++)
		for(int j = 0; j < (1<<7); j++){
			if(i == 0 and j == 0)
				kaps[i][j] = 1;
			else if(i%3 != 2 and i%3 != j%2)
				kaps[i][j] = 0;
			else
				kaps[i][j] = kaps[i/3][j/2];
		}

	for(int i = 0; i < (1<<7); i++){

		for(int j = 0; j < 159323; j++){
			if(prec[j] <= 0)
				dp[j] = a[i*(1<<13) - prec[j]];
			else
				dp[j] = dp[j - prec[j]] + dp[j - prec[j]*2];
		}

		for(int j = 1; j <= m; j++)
			if(kaps[q[j].st ][i ] )
				cvp[j] += dp[q[j].nd];
	}
	for(int i = 1; i <= m; i++)
		printf("%d\n",cvp[i]);
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:60:16: warning: unused variable 'say' [-Wunused-variable]
   int bit = 0, say = 0, son = 0, crp = 1;
                ^~~
snake_escaping.cpp:53: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:56:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
   ~~~~~^~~~~~~~~~
snake_escaping.cpp:62: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 76 ms 9592 KB Output is correct
2 Correct 56 ms 9592 KB Output is correct
3 Correct 57 ms 9628 KB Output is correct
4 Correct 56 ms 9628 KB Output is correct
5 Correct 58 ms 9704 KB Output is correct
6 Correct 60 ms 9704 KB Output is correct
7 Correct 56 ms 9764 KB Output is correct
8 Correct 62 ms 9764 KB Output is correct
9 Correct 56 ms 9784 KB Output is correct
10 Correct 56 ms 10064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 9592 KB Output is correct
2 Correct 56 ms 9592 KB Output is correct
3 Correct 57 ms 9628 KB Output is correct
4 Correct 56 ms 9628 KB Output is correct
5 Correct 58 ms 9704 KB Output is correct
6 Correct 60 ms 9704 KB Output is correct
7 Correct 56 ms 9764 KB Output is correct
8 Correct 62 ms 9764 KB Output is correct
9 Correct 56 ms 9784 KB Output is correct
10 Correct 56 ms 10064 KB Output is correct
11 Correct 1187 ms 25720 KB Output is correct
12 Correct 1055 ms 25720 KB Output is correct
13 Correct 1012 ms 25720 KB Output is correct
14 Correct 958 ms 25720 KB Output is correct
15 Correct 901 ms 25720 KB Output is correct
16 Correct 1000 ms 25720 KB Output is correct
17 Correct 1084 ms 25720 KB Output is correct
18 Correct 1037 ms 26552 KB Output is correct
19 Correct 1014 ms 26552 KB Output is correct
20 Correct 1004 ms 26552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 9592 KB Output is correct
2 Correct 56 ms 9592 KB Output is correct
3 Correct 57 ms 9628 KB Output is correct
4 Correct 56 ms 9628 KB Output is correct
5 Correct 58 ms 9704 KB Output is correct
6 Correct 60 ms 9704 KB Output is correct
7 Correct 56 ms 9764 KB Output is correct
8 Correct 62 ms 9764 KB Output is correct
9 Correct 56 ms 9784 KB Output is correct
10 Correct 56 ms 10064 KB Output is correct
11 Correct 1187 ms 25720 KB Output is correct
12 Correct 1055 ms 25720 KB Output is correct
13 Correct 1012 ms 25720 KB Output is correct
14 Correct 958 ms 25720 KB Output is correct
15 Correct 901 ms 25720 KB Output is correct
16 Correct 1000 ms 25720 KB Output is correct
17 Correct 1084 ms 25720 KB Output is correct
18 Correct 1037 ms 26552 KB Output is correct
19 Correct 1014 ms 26552 KB Output is correct
20 Correct 1004 ms 26552 KB Output is correct
21 Incorrect 1208 ms 26552 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 9592 KB Output is correct
2 Correct 56 ms 9592 KB Output is correct
3 Correct 57 ms 9628 KB Output is correct
4 Correct 56 ms 9628 KB Output is correct
5 Correct 58 ms 9704 KB Output is correct
6 Correct 60 ms 9704 KB Output is correct
7 Correct 56 ms 9764 KB Output is correct
8 Correct 62 ms 9764 KB Output is correct
9 Correct 56 ms 9784 KB Output is correct
10 Correct 56 ms 10064 KB Output is correct
11 Incorrect 197 ms 26552 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 9592 KB Output is correct
2 Correct 56 ms 9592 KB Output is correct
3 Correct 57 ms 9628 KB Output is correct
4 Correct 56 ms 9628 KB Output is correct
5 Correct 58 ms 9704 KB Output is correct
6 Correct 60 ms 9704 KB Output is correct
7 Correct 56 ms 9764 KB Output is correct
8 Correct 62 ms 9764 KB Output is correct
9 Correct 56 ms 9784 KB Output is correct
10 Correct 56 ms 10064 KB Output is correct
11 Correct 1187 ms 25720 KB Output is correct
12 Correct 1055 ms 25720 KB Output is correct
13 Correct 1012 ms 25720 KB Output is correct
14 Correct 958 ms 25720 KB Output is correct
15 Correct 901 ms 25720 KB Output is correct
16 Correct 1000 ms 25720 KB Output is correct
17 Correct 1084 ms 25720 KB Output is correct
18 Correct 1037 ms 26552 KB Output is correct
19 Correct 1014 ms 26552 KB Output is correct
20 Correct 1004 ms 26552 KB Output is correct
21 Incorrect 1208 ms 26552 KB Output isn't correct
22 Halted 0 ms 0 KB -