Submission #66983

# Submission time Handle Problem Language Result Execution time Memory
66983 2018-08-13T06:42:14 Z ekrem Snake Escaping (JOI18_snake_escaping) C++
75 / 100
2000 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[(1<<20)+10], dp[N], prec[N], cvp[1000005], kaps[3000][200];
char c;
pair < int , int > q[1000005];

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	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 say = 0, son = 0, crp = 1;
		long long bit = 0;
		for(int i = 1; i <= n; i++){
			scanf(" %c" ,&c);
			bit *= 3;
			bit += (c == '?') ? 2 : c - '0';
		}
		for(int say = 1; say <= 13; say++){
			son += crp*(bit%3);
			crp *= 3;
			bit/=3;
		}
		// cout << bit << " , " << son << endl;
		q[i] = mp(bit, son);
	}

	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 < 1594323; 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:43:7: warning: unused variable 'say' [-Wunused-variable]
   int say = 0, son = 0, crp = 1;
       ^~~
snake_escaping.cpp:35: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:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c",&c);
   ~~~~~^~~~~~~~~~
snake_escaping.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c" ,&c);
    ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 407 ms 14584 KB Output is correct
2 Correct 481 ms 14692 KB Output is correct
3 Correct 478 ms 14768 KB Output is correct
4 Correct 480 ms 14768 KB Output is correct
5 Correct 443 ms 14972 KB Output is correct
6 Correct 447 ms 14972 KB Output is correct
7 Correct 443 ms 14972 KB Output is correct
8 Correct 506 ms 14972 KB Output is correct
9 Correct 484 ms 14972 KB Output is correct
10 Correct 523 ms 14972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 14584 KB Output is correct
2 Correct 481 ms 14692 KB Output is correct
3 Correct 478 ms 14768 KB Output is correct
4 Correct 480 ms 14768 KB Output is correct
5 Correct 443 ms 14972 KB Output is correct
6 Correct 447 ms 14972 KB Output is correct
7 Correct 443 ms 14972 KB Output is correct
8 Correct 506 ms 14972 KB Output is correct
9 Correct 484 ms 14972 KB Output is correct
10 Correct 523 ms 14972 KB Output is correct
11 Correct 1531 ms 30432 KB Output is correct
12 Correct 1731 ms 30432 KB Output is correct
13 Correct 1396 ms 30432 KB Output is correct
14 Correct 1750 ms 30432 KB Output is correct
15 Correct 1536 ms 30664 KB Output is correct
16 Correct 1537 ms 30664 KB Output is correct
17 Correct 1553 ms 30664 KB Output is correct
18 Correct 1489 ms 31628 KB Output is correct
19 Correct 1572 ms 31628 KB Output is correct
20 Correct 1605 ms 31628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 14584 KB Output is correct
2 Correct 481 ms 14692 KB Output is correct
3 Correct 478 ms 14768 KB Output is correct
4 Correct 480 ms 14768 KB Output is correct
5 Correct 443 ms 14972 KB Output is correct
6 Correct 447 ms 14972 KB Output is correct
7 Correct 443 ms 14972 KB Output is correct
8 Correct 506 ms 14972 KB Output is correct
9 Correct 484 ms 14972 KB Output is correct
10 Correct 523 ms 14972 KB Output is correct
11 Correct 1531 ms 30432 KB Output is correct
12 Correct 1731 ms 30432 KB Output is correct
13 Correct 1396 ms 30432 KB Output is correct
14 Correct 1750 ms 30432 KB Output is correct
15 Correct 1536 ms 30664 KB Output is correct
16 Correct 1537 ms 30664 KB Output is correct
17 Correct 1553 ms 30664 KB Output is correct
18 Correct 1489 ms 31628 KB Output is correct
19 Correct 1572 ms 31628 KB Output is correct
20 Correct 1605 ms 31628 KB Output is correct
21 Correct 1725 ms 31628 KB Output is correct
22 Correct 1740 ms 32096 KB Output is correct
23 Correct 1700 ms 33620 KB Output is correct
24 Correct 1719 ms 33620 KB Output is correct
25 Correct 1737 ms 35328 KB Output is correct
26 Correct 1777 ms 35328 KB Output is correct
27 Correct 1899 ms 35328 KB Output is correct
28 Correct 1610 ms 36220 KB Output is correct
29 Correct 1626 ms 36220 KB Output is correct
30 Correct 1729 ms 36220 KB Output is correct
31 Correct 1888 ms 36220 KB Output is correct
32 Correct 1777 ms 38340 KB Output is correct
33 Correct 1696 ms 49224 KB Output is correct
34 Correct 1847 ms 54276 KB Output is correct
35 Correct 1871 ms 54704 KB Output is correct
36 Correct 1530 ms 54704 KB Output is correct
37 Correct 1676 ms 55192 KB Output is correct
38 Correct 1804 ms 55192 KB Output is correct
39 Correct 1791 ms 55192 KB Output is correct
40 Correct 1728 ms 55192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 14584 KB Output is correct
2 Correct 481 ms 14692 KB Output is correct
3 Correct 478 ms 14768 KB Output is correct
4 Correct 480 ms 14768 KB Output is correct
5 Correct 443 ms 14972 KB Output is correct
6 Correct 447 ms 14972 KB Output is correct
7 Correct 443 ms 14972 KB Output is correct
8 Correct 506 ms 14972 KB Output is correct
9 Correct 484 ms 14972 KB Output is correct
10 Correct 523 ms 14972 KB Output is correct
11 Correct 607 ms 55192 KB Output is correct
12 Correct 698 ms 55192 KB Output is correct
13 Correct 635 ms 55192 KB Output is correct
14 Correct 754 ms 55192 KB Output is correct
15 Correct 615 ms 55192 KB Output is correct
16 Correct 655 ms 55192 KB Output is correct
17 Correct 574 ms 55192 KB Output is correct
18 Correct 518 ms 55192 KB Output is correct
19 Correct 558 ms 55192 KB Output is correct
20 Correct 612 ms 55192 KB Output is correct
21 Correct 565 ms 56592 KB Output is correct
22 Correct 608 ms 58644 KB Output is correct
23 Correct 623 ms 60696 KB Output is correct
24 Correct 583 ms 61760 KB Output is correct
25 Correct 609 ms 61800 KB Output is correct
26 Correct 586 ms 61800 KB Output is correct
27 Correct 574 ms 61800 KB Output is correct
28 Correct 817 ms 61800 KB Output is correct
29 Correct 681 ms 61800 KB Output is correct
30 Correct 554 ms 61800 KB Output is correct
31 Correct 569 ms 61800 KB Output is correct
32 Correct 593 ms 61840 KB Output is correct
33 Correct 649 ms 61840 KB Output is correct
34 Correct 589 ms 61840 KB Output is correct
35 Correct 652 ms 61840 KB Output is correct
36 Correct 630 ms 61840 KB Output is correct
37 Correct 652 ms 61928 KB Output is correct
38 Correct 685 ms 61928 KB Output is correct
39 Correct 768 ms 61928 KB Output is correct
40 Correct 687 ms 63608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 14584 KB Output is correct
2 Correct 481 ms 14692 KB Output is correct
3 Correct 478 ms 14768 KB Output is correct
4 Correct 480 ms 14768 KB Output is correct
5 Correct 443 ms 14972 KB Output is correct
6 Correct 447 ms 14972 KB Output is correct
7 Correct 443 ms 14972 KB Output is correct
8 Correct 506 ms 14972 KB Output is correct
9 Correct 484 ms 14972 KB Output is correct
10 Correct 523 ms 14972 KB Output is correct
11 Correct 1531 ms 30432 KB Output is correct
12 Correct 1731 ms 30432 KB Output is correct
13 Correct 1396 ms 30432 KB Output is correct
14 Correct 1750 ms 30432 KB Output is correct
15 Correct 1536 ms 30664 KB Output is correct
16 Correct 1537 ms 30664 KB Output is correct
17 Correct 1553 ms 30664 KB Output is correct
18 Correct 1489 ms 31628 KB Output is correct
19 Correct 1572 ms 31628 KB Output is correct
20 Correct 1605 ms 31628 KB Output is correct
21 Correct 1725 ms 31628 KB Output is correct
22 Correct 1740 ms 32096 KB Output is correct
23 Correct 1700 ms 33620 KB Output is correct
24 Correct 1719 ms 33620 KB Output is correct
25 Correct 1737 ms 35328 KB Output is correct
26 Correct 1777 ms 35328 KB Output is correct
27 Correct 1899 ms 35328 KB Output is correct
28 Correct 1610 ms 36220 KB Output is correct
29 Correct 1626 ms 36220 KB Output is correct
30 Correct 1729 ms 36220 KB Output is correct
31 Correct 1888 ms 36220 KB Output is correct
32 Correct 1777 ms 38340 KB Output is correct
33 Correct 1696 ms 49224 KB Output is correct
34 Correct 1847 ms 54276 KB Output is correct
35 Correct 1871 ms 54704 KB Output is correct
36 Correct 1530 ms 54704 KB Output is correct
37 Correct 1676 ms 55192 KB Output is correct
38 Correct 1804 ms 55192 KB Output is correct
39 Correct 1791 ms 55192 KB Output is correct
40 Correct 1728 ms 55192 KB Output is correct
41 Correct 607 ms 55192 KB Output is correct
42 Correct 698 ms 55192 KB Output is correct
43 Correct 635 ms 55192 KB Output is correct
44 Correct 754 ms 55192 KB Output is correct
45 Correct 615 ms 55192 KB Output is correct
46 Correct 655 ms 55192 KB Output is correct
47 Correct 574 ms 55192 KB Output is correct
48 Correct 518 ms 55192 KB Output is correct
49 Correct 558 ms 55192 KB Output is correct
50 Correct 612 ms 55192 KB Output is correct
51 Correct 565 ms 56592 KB Output is correct
52 Correct 608 ms 58644 KB Output is correct
53 Correct 623 ms 60696 KB Output is correct
54 Correct 583 ms 61760 KB Output is correct
55 Correct 609 ms 61800 KB Output is correct
56 Correct 586 ms 61800 KB Output is correct
57 Correct 574 ms 61800 KB Output is correct
58 Correct 817 ms 61800 KB Output is correct
59 Correct 681 ms 61800 KB Output is correct
60 Correct 554 ms 61800 KB Output is correct
61 Correct 569 ms 61800 KB Output is correct
62 Correct 593 ms 61840 KB Output is correct
63 Correct 649 ms 61840 KB Output is correct
64 Correct 589 ms 61840 KB Output is correct
65 Correct 652 ms 61840 KB Output is correct
66 Correct 630 ms 61840 KB Output is correct
67 Correct 652 ms 61928 KB Output is correct
68 Correct 685 ms 61928 KB Output is correct
69 Correct 768 ms 61928 KB Output is correct
70 Correct 687 ms 63608 KB Output is correct
71 Execution timed out 2051 ms 66560 KB Time limit exceeded
72 Halted 0 ms 0 KB -