답안 #66907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66907 2018-08-12T18:44:43 Z hamzqq9 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
845 ms 66560 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 100000000000000
#define MOD 1000000007
#define N 3005
#define MAX 10000006
#define LOG 22
#define L 7
#define R 13
using namespace std;

int n,q,l,Qno,Right;
int cnt[1594325],ans[pw(20)+5];
int po3[20],pos[1594325];
char val[pw(20)+5],s[pw(20)+5];
vector<ii> queries[pw(L)];
bool oops[1594325];

int get_2_rep(int val) {

	int res=0;
	int curpw=1;

	while(val) {

		res+=curpw*(val%3);

		val/=3;

		curpw*=2;

	}

	return res;

}

int get_2(int val) {

	int cur=0;

	while(val) {

		if(val%3==2) return cur;

		cur++;

		val/=3;

	}

	return -1;

}

void do_dp(int value) {

	for(int i=0;i<1594323;i++) {

		if(oops[i]) cnt[i]=val[value*pw(R)+pos[i]];
		else cnt[i]=cnt[i-po3[pos[i]]]+cnt[i-2*po3[pos[i]]];

	}

}

void pre_cal() {

	for(int i=0;i<1594323;i++) {

		pos[i]=get_2(i);

		if(pos[i]==-1) {
		
			oops[i]=true;

			pos[i]=get_2_rep(i);
		
		}

	}

}

void back_track(int cur,int val) {

	if(cur==L) {

		queries[val].pb({Right,Qno});

		return ;

	}

	if(s[cur]=='?') {

		back_track(cur+1,val);
		back_track(cur+1,val+pw(L-cur-1));

	}
	else back_track(cur+1,val+pw(L-cur-1)*(s[cur]=='1'));

}

int get_value(int bas,int son) {

	int res=0;

	for(int i=bas;i<=son;i++) {

		res=res*3+(s[i]=='?'?2:(s[i]-'0'));

	}

	return res;

}

int main() {
 
	//freopen("input.txt","r",stdin);
 
	po3[0]=1;

 	for(int i=1;i<=15;i++) po3[i]=po3[i-1]*3;

	scanf("%d %d",&l,&q);

	n=pw(l);

	scanf("%s",s);

	for(int i=0;i<n;i++) val[i]=s[i]-'0';

	for(int i=1;i<=q;i++) {

		scanf("%s",s+20-l);

		for(int i=0;i<20-l;i++) s[i]='0';

		Right=get_value(7,19);

		Qno=i;

		back_track(0,0);

	}

	pre_cal();

	for(int i=0;i<pw(L);i++) {

		if(!sz(queries[i])) continue ;

		do_dp(i);

		for(ii Q:queries[i]) { // Q.st-->right Q.nd-->quno

			ans[Q.nd]+=cnt[Q.st];

		}

	}

	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);

} 	
 

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&l,&q);
  ~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:145:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s);
  ~~~~~^~~~~~~~
snake_escaping.cpp:151:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s+20-l);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 35 ms 13160 KB Output is correct
3 Correct 34 ms 13160 KB Output is correct
4 Correct 31 ms 13160 KB Output is correct
5 Correct 30 ms 13160 KB Output is correct
6 Correct 27 ms 13216 KB Output is correct
7 Correct 29 ms 13312 KB Output is correct
8 Correct 39 ms 13312 KB Output is correct
9 Correct 34 ms 13312 KB Output is correct
10 Correct 30 ms 13312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 35 ms 13160 KB Output is correct
3 Correct 34 ms 13160 KB Output is correct
4 Correct 31 ms 13160 KB Output is correct
5 Correct 30 ms 13160 KB Output is correct
6 Correct 27 ms 13216 KB Output is correct
7 Correct 29 ms 13312 KB Output is correct
8 Correct 39 ms 13312 KB Output is correct
9 Correct 34 ms 13312 KB Output is correct
10 Correct 30 ms 13312 KB Output is correct
11 Correct 375 ms 29156 KB Output is correct
12 Correct 364 ms 29156 KB Output is correct
13 Correct 337 ms 29156 KB Output is correct
14 Correct 339 ms 29156 KB Output is correct
15 Correct 367 ms 29156 KB Output is correct
16 Correct 358 ms 29156 KB Output is correct
17 Correct 329 ms 29156 KB Output is correct
18 Correct 313 ms 30132 KB Output is correct
19 Correct 309 ms 30132 KB Output is correct
20 Correct 381 ms 30132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 35 ms 13160 KB Output is correct
3 Correct 34 ms 13160 KB Output is correct
4 Correct 31 ms 13160 KB Output is correct
5 Correct 30 ms 13160 KB Output is correct
6 Correct 27 ms 13216 KB Output is correct
7 Correct 29 ms 13312 KB Output is correct
8 Correct 39 ms 13312 KB Output is correct
9 Correct 34 ms 13312 KB Output is correct
10 Correct 30 ms 13312 KB Output is correct
11 Correct 375 ms 29156 KB Output is correct
12 Correct 364 ms 29156 KB Output is correct
13 Correct 337 ms 29156 KB Output is correct
14 Correct 339 ms 29156 KB Output is correct
15 Correct 367 ms 29156 KB Output is correct
16 Correct 358 ms 29156 KB Output is correct
17 Correct 329 ms 29156 KB Output is correct
18 Correct 313 ms 30132 KB Output is correct
19 Correct 309 ms 30132 KB Output is correct
20 Correct 381 ms 30132 KB Output is correct
21 Correct 436 ms 30132 KB Output is correct
22 Correct 424 ms 30132 KB Output is correct
23 Correct 394 ms 30132 KB Output is correct
24 Correct 391 ms 30132 KB Output is correct
25 Correct 440 ms 30248 KB Output is correct
26 Correct 392 ms 30248 KB Output is correct
27 Correct 403 ms 30248 KB Output is correct
28 Correct 328 ms 31152 KB Output is correct
29 Correct 284 ms 31152 KB Output is correct
30 Correct 379 ms 31152 KB Output is correct
31 Correct 447 ms 31152 KB Output is correct
32 Correct 428 ms 31152 KB Output is correct
33 Correct 515 ms 31152 KB Output is correct
34 Correct 392 ms 31152 KB Output is correct
35 Correct 504 ms 31152 KB Output is correct
36 Correct 303 ms 31152 KB Output is correct
37 Correct 396 ms 31152 KB Output is correct
38 Correct 298 ms 31152 KB Output is correct
39 Correct 384 ms 31152 KB Output is correct
40 Correct 348 ms 31152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 35 ms 13160 KB Output is correct
3 Correct 34 ms 13160 KB Output is correct
4 Correct 31 ms 13160 KB Output is correct
5 Correct 30 ms 13160 KB Output is correct
6 Correct 27 ms 13216 KB Output is correct
7 Correct 29 ms 13312 KB Output is correct
8 Correct 39 ms 13312 KB Output is correct
9 Correct 34 ms 13312 KB Output is correct
10 Correct 30 ms 13312 KB Output is correct
11 Correct 656 ms 31152 KB Output is correct
12 Correct 596 ms 31152 KB Output is correct
13 Correct 554 ms 31152 KB Output is correct
14 Correct 569 ms 31152 KB Output is correct
15 Correct 673 ms 31408 KB Output is correct
16 Correct 590 ms 31408 KB Output is correct
17 Correct 564 ms 31408 KB Output is correct
18 Runtime error 845 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 13140 KB Output is correct
2 Correct 35 ms 13160 KB Output is correct
3 Correct 34 ms 13160 KB Output is correct
4 Correct 31 ms 13160 KB Output is correct
5 Correct 30 ms 13160 KB Output is correct
6 Correct 27 ms 13216 KB Output is correct
7 Correct 29 ms 13312 KB Output is correct
8 Correct 39 ms 13312 KB Output is correct
9 Correct 34 ms 13312 KB Output is correct
10 Correct 30 ms 13312 KB Output is correct
11 Correct 375 ms 29156 KB Output is correct
12 Correct 364 ms 29156 KB Output is correct
13 Correct 337 ms 29156 KB Output is correct
14 Correct 339 ms 29156 KB Output is correct
15 Correct 367 ms 29156 KB Output is correct
16 Correct 358 ms 29156 KB Output is correct
17 Correct 329 ms 29156 KB Output is correct
18 Correct 313 ms 30132 KB Output is correct
19 Correct 309 ms 30132 KB Output is correct
20 Correct 381 ms 30132 KB Output is correct
21 Correct 436 ms 30132 KB Output is correct
22 Correct 424 ms 30132 KB Output is correct
23 Correct 394 ms 30132 KB Output is correct
24 Correct 391 ms 30132 KB Output is correct
25 Correct 440 ms 30248 KB Output is correct
26 Correct 392 ms 30248 KB Output is correct
27 Correct 403 ms 30248 KB Output is correct
28 Correct 328 ms 31152 KB Output is correct
29 Correct 284 ms 31152 KB Output is correct
30 Correct 379 ms 31152 KB Output is correct
31 Correct 447 ms 31152 KB Output is correct
32 Correct 428 ms 31152 KB Output is correct
33 Correct 515 ms 31152 KB Output is correct
34 Correct 392 ms 31152 KB Output is correct
35 Correct 504 ms 31152 KB Output is correct
36 Correct 303 ms 31152 KB Output is correct
37 Correct 396 ms 31152 KB Output is correct
38 Correct 298 ms 31152 KB Output is correct
39 Correct 384 ms 31152 KB Output is correct
40 Correct 348 ms 31152 KB Output is correct
41 Correct 656 ms 31152 KB Output is correct
42 Correct 596 ms 31152 KB Output is correct
43 Correct 554 ms 31152 KB Output is correct
44 Correct 569 ms 31152 KB Output is correct
45 Correct 673 ms 31408 KB Output is correct
46 Correct 590 ms 31408 KB Output is correct
47 Correct 564 ms 31408 KB Output is correct
48 Runtime error 845 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
49 Halted 0 ms 0 KB -