답안 #888005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888005 2023-12-15T18:15:19 Z hariaakas646 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1807 ms 26384 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(x) scanf("%d", &x)
#define sclld(x) scanf("%lld", &x)
#define frange(i, n) for(int i=0; i<n; i++)
#define forr(i, l, r) for(int i=l; i<r; i++)
#define all(vec) vec.begin(), vec.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

typedef long long lli;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<lli> vll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> seti;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int main() {
	// usaco();
	int l, q;
	cin >> l >> q;
	string str;
	cin >> str;

	vi mv(1<<l);

	frange(i, 1<<l) {
		mv[i] = str[i] - '0';
	}

	int v = 1;



	frange(i, l) v *= 3;

	vi tot(v);
	vi po3(l+1);
	po3[0] = 1;
	forr(i, 1, l+1) po3[i] = po3[i-1] * 3;
	frange(i, v) {
		int li=0;
		int r = 0;
		int x = 0;
		int k = i;
		bool done = false;
		frange(j, l) {
			if(k % 3 == 1) {
				x += po3[j];
				li += po3[j];
				r += po3[j];
			}
			else if(k % 3 == 2) {
				x += po3[j] * 2;
				if(!done)
					{r += po3[j]; done = true;}
				else {
					li += po3[j] * 2;;
					r += po3[j] * 2;
				}
			}
			k /= 3;
		}
		k = i;
		if(!done) {
			int x2 = 0;
			frange(j, l) {
				if(k % 3 == 1) {
					x2 += (1<<j);
				}
				k /= 3;
			}
			tot[x] = mv[x2];
		}
		else {
			// cout << x << " " << li << " " << r << "\n";
			tot[x] = tot[li] + tot[r];
		}
	}

	frange(_, q) {
		string str;
		cin >> str;
		int v = 0;
		frange(i, l) {
			if(str[l-i-1] == '1') v += po3[i];
			else if(str[l-i-1] == '?') v += 2*po3[i];
		}
		// int to = 0;
		// frange(i, 1<<l) {
		// 	bool done = true;
		// 	frange(j, l) {
		// 		if(str[j] == '?') continue;
		// 		else {
		// 			if(bool(str[j] - '0') != bool(i&(1<<(l-j-1)))) done = false;
		// 		}
		// 	}
		// 	if(done) to += mv[i];
		// }
		// cout << str << " " << v << " ";
		cout << tot[v] << "\n";
	}
}

Compilation message

snake_escaping.cpp: In function 'void usaco()':
snake_escaping.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 1457 ms 4508 KB Output is correct
12 Correct 1452 ms 4340 KB Output is correct
13 Correct 1460 ms 3456 KB Output is correct
14 Correct 1501 ms 3544 KB Output is correct
15 Correct 1510 ms 4664 KB Output is correct
16 Correct 1502 ms 3672 KB Output is correct
17 Correct 1480 ms 3632 KB Output is correct
18 Correct 1421 ms 5556 KB Output is correct
19 Correct 1441 ms 2644 KB Output is correct
20 Correct 1466 ms 4100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 1457 ms 4508 KB Output is correct
12 Correct 1452 ms 4340 KB Output is correct
13 Correct 1460 ms 3456 KB Output is correct
14 Correct 1501 ms 3544 KB Output is correct
15 Correct 1510 ms 4664 KB Output is correct
16 Correct 1502 ms 3672 KB Output is correct
17 Correct 1480 ms 3632 KB Output is correct
18 Correct 1421 ms 5556 KB Output is correct
19 Correct 1441 ms 2644 KB Output is correct
20 Correct 1466 ms 4100 KB Output is correct
21 Correct 1656 ms 14044 KB Output is correct
22 Correct 1717 ms 24404 KB Output is correct
23 Correct 1651 ms 23612 KB Output is correct
24 Correct 1665 ms 23344 KB Output is correct
25 Correct 1632 ms 25424 KB Output is correct
26 Correct 1667 ms 23764 KB Output is correct
27 Correct 1669 ms 23916 KB Output is correct
28 Correct 1580 ms 26384 KB Output is correct
29 Correct 1658 ms 22344 KB Output is correct
30 Correct 1621 ms 24644 KB Output is correct
31 Correct 1666 ms 24404 KB Output is correct
32 Correct 1682 ms 24452 KB Output is correct
33 Correct 1699 ms 23260 KB Output is correct
34 Correct 1727 ms 23248 KB Output is correct
35 Correct 1807 ms 23688 KB Output is correct
36 Correct 1548 ms 22648 KB Output is correct
37 Correct 1633 ms 24432 KB Output is correct
38 Correct 1674 ms 22388 KB Output is correct
39 Correct 1713 ms 23432 KB Output is correct
40 Correct 1664 ms 23336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Runtime error 29 ms 11184 KB Execution killed with signal 6
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 600 KB Output is correct
2 Correct 6 ms 604 KB Output is correct
3 Correct 5 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 5 ms 604 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 6 ms 604 KB Output is correct
10 Correct 8 ms 604 KB Output is correct
11 Correct 1457 ms 4508 KB Output is correct
12 Correct 1452 ms 4340 KB Output is correct
13 Correct 1460 ms 3456 KB Output is correct
14 Correct 1501 ms 3544 KB Output is correct
15 Correct 1510 ms 4664 KB Output is correct
16 Correct 1502 ms 3672 KB Output is correct
17 Correct 1480 ms 3632 KB Output is correct
18 Correct 1421 ms 5556 KB Output is correct
19 Correct 1441 ms 2644 KB Output is correct
20 Correct 1466 ms 4100 KB Output is correct
21 Correct 1656 ms 14044 KB Output is correct
22 Correct 1717 ms 24404 KB Output is correct
23 Correct 1651 ms 23612 KB Output is correct
24 Correct 1665 ms 23344 KB Output is correct
25 Correct 1632 ms 25424 KB Output is correct
26 Correct 1667 ms 23764 KB Output is correct
27 Correct 1669 ms 23916 KB Output is correct
28 Correct 1580 ms 26384 KB Output is correct
29 Correct 1658 ms 22344 KB Output is correct
30 Correct 1621 ms 24644 KB Output is correct
31 Correct 1666 ms 24404 KB Output is correct
32 Correct 1682 ms 24452 KB Output is correct
33 Correct 1699 ms 23260 KB Output is correct
34 Correct 1727 ms 23248 KB Output is correct
35 Correct 1807 ms 23688 KB Output is correct
36 Correct 1548 ms 22648 KB Output is correct
37 Correct 1633 ms 24432 KB Output is correct
38 Correct 1674 ms 22388 KB Output is correct
39 Correct 1713 ms 23432 KB Output is correct
40 Correct 1664 ms 23336 KB Output is correct
41 Runtime error 29 ms 11184 KB Execution killed with signal 6
42 Halted 0 ms 0 KB -