답안 #376491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376491 2021-03-11T14:57:54 Z astoria Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
422 ms 32620 KB
#include "bits/stdc++.h"
using namespace std;

int l,q,n;
int pw[25]; 

int fast_mod(const int input, const int ceil) {
    // apply the modulo operator only when needed
    // (i.e. when the input is greater than the ceiling)
    return input >= ceil ? input % ceil : input;
    // NB: the assumption here is that the numbers are positive
}

/*bool comp(int a, int b){
	vector<int> x,y;
	int cntx=0,cnty=0;
	for(int j=0; j<l; j++){
		int cr = fast_mod(a,3); a/=3;
		if(cr==2) cntx++;
	}
	for(int j=0; j<l; j++){
		int cr = fast_mod(b,3); b/=3;
		if(cr==2) cnty++;
	}
	return cntx<cnty;
}*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>l>>q; n=1<<l;
	string s; cin>>s;
	int tox[n];
	for(int i=0; i<n; i++) tox[i] = s[i]-'0';
	
	pw[0]=1;
	int k=1; for(int i=1; i<=l; i++){ k*=3; pw[i]=k;}
	int ans[k]; memset(ans,0,sizeof(ans));
	
	int ord[k];
	for(int i=0; i<k; i++) ord[i]=i;
		
	for(int i=0; i<n; i++){
		bitset<13> b(i); int v=0;
		for(int j=0; j<l; j++) v+=(pw[j]*b[j]);
		int vk=v;
		int tot = 0;
		for(int j=0; j<l; j++){
			int cr = fast_mod(v,3); v/=3;
			tot += ((1<<j)*cr);
		}
		ans[vk] = tox[tot];
	}
		
	for(int ahc=0; ahc<k; ahc++){
		int v = ahc, tk = ahc, tt = ahc, vk = ahc;
		for(int i=0; i<l; i++){
			int cr = fast_mod(v,3); v/=3;
			if(cr==2){
				tk-=(2*pw[i]);
				tt-=(1*pw[i]);
				break;
			}
		}
		if(ans[vk]==0) ans[vk] = ans[tk]+ans[tt];
	}
	
	/*for(int ahc=0; ahc<k; ahc++){
		vector<int> v; int cr=ahc;
		for(int j=0; j<l; j++){
			v.push_back(cr%3); cr/=3;
		}
		for(int i=0; i<n; i++){
			bitset<13> b(i); bool f=1;
			for(int j=0; j<l; j++){
				if(v[j]!=2 && (b[j]!=v[j])){ f=0; break;}
			}
			if(f) ans[ahc] += tox[i];
		}
	}*/
	
	
	for(int ahc=0; ahc<q; ahc++){
		string s; cin>>s;
		int qr=0;
		for(int i=0; i<l; i++){
			int pwer = l-i-1;
			if(s[i]=='1') qr += (pw[pwer]);
			if(s[i]=='?') qr += (2*pw[pwer]);
		}
		cout<<ans[qr]<<"\n";
	}
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:40:6: warning: variable 'ord' set but not used [-Wunused-but-set-variable]
   40 |  int ord[k];
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 233 ms 4844 KB Output is correct
12 Correct 245 ms 4460 KB Output is correct
13 Correct 246 ms 3820 KB Output is correct
14 Correct 253 ms 3836 KB Output is correct
15 Correct 254 ms 4844 KB Output is correct
16 Correct 289 ms 4076 KB Output is correct
17 Correct 287 ms 3936 KB Output is correct
18 Correct 194 ms 5868 KB Output is correct
19 Correct 224 ms 2796 KB Output is correct
20 Correct 242 ms 4460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 233 ms 4844 KB Output is correct
12 Correct 245 ms 4460 KB Output is correct
13 Correct 246 ms 3820 KB Output is correct
14 Correct 253 ms 3836 KB Output is correct
15 Correct 254 ms 4844 KB Output is correct
16 Correct 289 ms 4076 KB Output is correct
17 Correct 287 ms 3936 KB Output is correct
18 Correct 194 ms 5868 KB Output is correct
19 Correct 224 ms 2796 KB Output is correct
20 Correct 242 ms 4460 KB Output is correct
21 Correct 286 ms 29336 KB Output is correct
22 Correct 308 ms 30748 KB Output is correct
23 Correct 389 ms 29932 KB Output is correct
24 Correct 366 ms 29624 KB Output is correct
25 Correct 330 ms 31816 KB Output is correct
26 Correct 401 ms 30188 KB Output is correct
27 Correct 408 ms 30088 KB Output is correct
28 Correct 230 ms 32620 KB Output is correct
29 Correct 286 ms 28656 KB Output is correct
30 Correct 299 ms 30848 KB Output is correct
31 Correct 347 ms 30700 KB Output is correct
32 Correct 377 ms 30700 KB Output is correct
33 Correct 335 ms 29676 KB Output is correct
34 Correct 384 ms 29548 KB Output is correct
35 Correct 410 ms 30060 KB Output is correct
36 Correct 228 ms 28644 KB Output is correct
37 Correct 283 ms 30572 KB Output is correct
38 Correct 287 ms 28652 KB Output is correct
39 Correct 387 ms 29932 KB Output is correct
40 Correct 422 ms 29784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Runtime error 13 ms 11152 KB Execution killed with signal 7
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 2 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 2 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 233 ms 4844 KB Output is correct
12 Correct 245 ms 4460 KB Output is correct
13 Correct 246 ms 3820 KB Output is correct
14 Correct 253 ms 3836 KB Output is correct
15 Correct 254 ms 4844 KB Output is correct
16 Correct 289 ms 4076 KB Output is correct
17 Correct 287 ms 3936 KB Output is correct
18 Correct 194 ms 5868 KB Output is correct
19 Correct 224 ms 2796 KB Output is correct
20 Correct 242 ms 4460 KB Output is correct
21 Correct 286 ms 29336 KB Output is correct
22 Correct 308 ms 30748 KB Output is correct
23 Correct 389 ms 29932 KB Output is correct
24 Correct 366 ms 29624 KB Output is correct
25 Correct 330 ms 31816 KB Output is correct
26 Correct 401 ms 30188 KB Output is correct
27 Correct 408 ms 30088 KB Output is correct
28 Correct 230 ms 32620 KB Output is correct
29 Correct 286 ms 28656 KB Output is correct
30 Correct 299 ms 30848 KB Output is correct
31 Correct 347 ms 30700 KB Output is correct
32 Correct 377 ms 30700 KB Output is correct
33 Correct 335 ms 29676 KB Output is correct
34 Correct 384 ms 29548 KB Output is correct
35 Correct 410 ms 30060 KB Output is correct
36 Correct 228 ms 28644 KB Output is correct
37 Correct 283 ms 30572 KB Output is correct
38 Correct 287 ms 28652 KB Output is correct
39 Correct 387 ms 29932 KB Output is correct
40 Correct 422 ms 29784 KB Output is correct
41 Runtime error 13 ms 11152 KB Execution killed with signal 7
42 Halted 0 ms 0 KB -