Submission #533246

# Submission time Handle Problem Language Result Execution time Memory
533246 2022-03-05T07:45:50 Z browntoad Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
451 ms 26260 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
//#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char> 
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=1594323;
const double PI=acos(-1);

ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll m=mod){
    return pw(a,m-2);
}

//=======================================================================================

int n,q;
string str;
int dp[maxn], pw3[15];
void SOS(){
	REP(i,(1<<n)){
		int ac=0;
		REP(j,n){
			if (i&(1<<j)) ac+=pw3[j];
		}
		dp[ac]=str[i]-'0';
	}
	REP(i,n){
		string cur;
		REP(j,n){
			cur+='0';
		}
		REP(j,pw3[n]){
			if (cur[i]=='2'){
				dp[j]+=dp[j-2*pw3[i]]+dp[j-pw3[i]];
			}
			REP(k,n){
				if (cur[k]!='2') {
					cur[k]++;
					break;
				}
				cur[k]='0';
			}
		}
	}
}
signed main (){
    IOS();
    cin>>n>>q;
    cin>>str;
    pw3[0]=1;
    REP1(i,14){
    	pw3[i]=pw3[i-1]*3;
    }
    SOS();
    string in;
    int cur=0;
    REP(i,q){
    	cur=0;
    	cin>>in;
    	reverse(ALL(in));
    	REP(i,n){
    		if (in[i]=='1'){
    			cur+=pw3[i];
    		}
    		else if (in[i]=='?'){
    			cur+=pw3[i]*2;
    		}
    	}
    	//cout<<cur<<endl;
    	cout<<dp[cur]<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 214 ms 15204 KB Output is correct
12 Correct 217 ms 14900 KB Output is correct
13 Correct 234 ms 14180 KB Output is correct
14 Correct 231 ms 14284 KB Output is correct
15 Correct 238 ms 15276 KB Output is correct
16 Correct 233 ms 14404 KB Output is correct
17 Correct 233 ms 14404 KB Output is correct
18 Correct 186 ms 16188 KB Output is correct
19 Correct 266 ms 13276 KB Output is correct
20 Correct 260 ms 14996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 214 ms 15204 KB Output is correct
12 Correct 217 ms 14900 KB Output is correct
13 Correct 234 ms 14180 KB Output is correct
14 Correct 231 ms 14284 KB Output is correct
15 Correct 238 ms 15276 KB Output is correct
16 Correct 233 ms 14404 KB Output is correct
17 Correct 233 ms 14404 KB Output is correct
18 Correct 186 ms 16188 KB Output is correct
19 Correct 266 ms 13276 KB Output is correct
20 Correct 260 ms 14996 KB Output is correct
21 Correct 407 ms 24160 KB Output is correct
22 Correct 358 ms 24420 KB Output is correct
23 Correct 391 ms 23316 KB Output is correct
24 Correct 397 ms 23240 KB Output is correct
25 Correct 346 ms 25244 KB Output is correct
26 Correct 430 ms 23732 KB Output is correct
27 Correct 451 ms 23596 KB Output is correct
28 Correct 316 ms 26260 KB Output is correct
29 Correct 349 ms 22176 KB Output is correct
30 Correct 373 ms 24440 KB Output is correct
31 Correct 420 ms 24316 KB Output is correct
32 Correct 386 ms 24136 KB Output is correct
33 Correct 368 ms 23096 KB Output is correct
34 Correct 440 ms 23252 KB Output is correct
35 Correct 435 ms 23772 KB Output is correct
36 Correct 273 ms 22224 KB Output is correct
37 Correct 357 ms 24220 KB Output is correct
38 Correct 337 ms 22216 KB Output is correct
39 Correct 391 ms 23428 KB Output is correct
40 Correct 390 ms 23316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Runtime error 9 ms 5032 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 4 ms 460 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 4 ms 460 KB Output is correct
5 Correct 4 ms 460 KB Output is correct
6 Correct 4 ms 460 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 214 ms 15204 KB Output is correct
12 Correct 217 ms 14900 KB Output is correct
13 Correct 234 ms 14180 KB Output is correct
14 Correct 231 ms 14284 KB Output is correct
15 Correct 238 ms 15276 KB Output is correct
16 Correct 233 ms 14404 KB Output is correct
17 Correct 233 ms 14404 KB Output is correct
18 Correct 186 ms 16188 KB Output is correct
19 Correct 266 ms 13276 KB Output is correct
20 Correct 260 ms 14996 KB Output is correct
21 Correct 407 ms 24160 KB Output is correct
22 Correct 358 ms 24420 KB Output is correct
23 Correct 391 ms 23316 KB Output is correct
24 Correct 397 ms 23240 KB Output is correct
25 Correct 346 ms 25244 KB Output is correct
26 Correct 430 ms 23732 KB Output is correct
27 Correct 451 ms 23596 KB Output is correct
28 Correct 316 ms 26260 KB Output is correct
29 Correct 349 ms 22176 KB Output is correct
30 Correct 373 ms 24440 KB Output is correct
31 Correct 420 ms 24316 KB Output is correct
32 Correct 386 ms 24136 KB Output is correct
33 Correct 368 ms 23096 KB Output is correct
34 Correct 440 ms 23252 KB Output is correct
35 Correct 435 ms 23772 KB Output is correct
36 Correct 273 ms 22224 KB Output is correct
37 Correct 357 ms 24220 KB Output is correct
38 Correct 337 ms 22216 KB Output is correct
39 Correct 391 ms 23428 KB Output is correct
40 Correct 390 ms 23316 KB Output is correct
41 Runtime error 9 ms 5032 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -