Submission #255182

# Submission time Handle Problem Language Result Execution time Memory
255182 2020-07-31T13:50:14 Z Atill83 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1239 ms 57080 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e6;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n, l, q;
string s;
int say[MAXN][2];
int ans[MAXN];

const int n37 = 2187;
const int n313 = 1594323;
int child[n313][2];
bool sub[n37][(1<<7)];
ll dp[n313];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>l>>q;

    cin>>s;

    for(int i = 0; i < q; i++){
        string t;
        cin>>t;
        for(int j = 0; j < min(l, 7); j++){
            say[i][0] += (t[j] == '?' ? 2 : t[j] - '0');
            say[i][0] *= 3;
        }
        say[i][0] /= 3;
        for(int j = 7; j < l; j++){
            say[i][1] += (t[j] == '?' ? 2 : t[j] - '0');
            say[i][1] *= 3;
        }
        say[i][1] /= 3;
    }

    for(int i = 0; i < n313; i++){
        int cur = i;
        child[i][0] = child[i][1] = -1;
        int cc = 1;
        for(int j = 0; j < 7; j++){
            if(cur % 3 == 2){
                child[i][0] = i - cc;
                child[i][1] = i - 2*cc;
                break;
            }
            cc *= 3;
            cur /= 3;
        }
    }


    for(int i = 0; i < n37; i++){
        for(int j = 0; j < (1<<7); j++){
            int cur1 = i, cur2 = j;
            bool tru = 1;
            for(int k = 0; k < 7; k++){
                if(cur1 % 3 != 2 && cur1 % 3 != cur2 % 2){
                    tru = 0;
                    break;
                }
                cur1 /= 3;
                cur2 /= 2;
            }
            sub[i][j] = tru;
        }
    }

    int rhs = max(0, l - 7);

    for(int j = 0; j < (1<<min(l, 7)); j++){
        
        for(int i = 0; i < n313; i++){
            if(child[i][0] == -1){
                int kal = 0;
                int cur = i;
                for(int k = 0; k < rhs; k++){
                    if(cur % 3) kal += (1<<k);
                    cur /= 3;
                }
                dp[i] = s[(j<<rhs) + kal] - '0';
            }else{
                dp[i] = dp[child[i][0]] + dp[child[i][1]];
            }
        }

        for(int i = 0; i < q; i++){
            if(!sub[say[i][0]][j]) continue;
            ans[i] += dp[say[i][1]];
        }
    }

    for(int i = 0; i < q; i++) 
        cout<<ans[i]<<endl;


    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 438 ms 25592 KB Output is correct
2 Correct 437 ms 25720 KB Output is correct
3 Correct 393 ms 25648 KB Output is correct
4 Correct 449 ms 25720 KB Output is correct
5 Correct 431 ms 25600 KB Output is correct
6 Correct 461 ms 25720 KB Output is correct
7 Correct 476 ms 25592 KB Output is correct
8 Correct 429 ms 25720 KB Output is correct
9 Correct 444 ms 25720 KB Output is correct
10 Correct 396 ms 25720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 25592 KB Output is correct
2 Correct 437 ms 25720 KB Output is correct
3 Correct 393 ms 25648 KB Output is correct
4 Correct 449 ms 25720 KB Output is correct
5 Correct 431 ms 25600 KB Output is correct
6 Correct 461 ms 25720 KB Output is correct
7 Correct 476 ms 25592 KB Output is correct
8 Correct 429 ms 25720 KB Output is correct
9 Correct 444 ms 25720 KB Output is correct
10 Correct 396 ms 25720 KB Output is correct
11 Correct 921 ms 52088 KB Output is correct
12 Correct 1079 ms 51704 KB Output is correct
13 Correct 982 ms 50936 KB Output is correct
14 Correct 914 ms 51192 KB Output is correct
15 Correct 1069 ms 52092 KB Output is correct
16 Correct 926 ms 51320 KB Output is correct
17 Correct 906 ms 51240 KB Output is correct
18 Correct 764 ms 53240 KB Output is correct
19 Correct 784 ms 50136 KB Output is correct
20 Correct 967 ms 51832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 25592 KB Output is correct
2 Correct 437 ms 25720 KB Output is correct
3 Correct 393 ms 25648 KB Output is correct
4 Correct 449 ms 25720 KB Output is correct
5 Correct 431 ms 25600 KB Output is correct
6 Correct 461 ms 25720 KB Output is correct
7 Correct 476 ms 25592 KB Output is correct
8 Correct 429 ms 25720 KB Output is correct
9 Correct 444 ms 25720 KB Output is correct
10 Correct 396 ms 25720 KB Output is correct
11 Correct 921 ms 52088 KB Output is correct
12 Correct 1079 ms 51704 KB Output is correct
13 Correct 982 ms 50936 KB Output is correct
14 Correct 914 ms 51192 KB Output is correct
15 Correct 1069 ms 52092 KB Output is correct
16 Correct 926 ms 51320 KB Output is correct
17 Correct 906 ms 51240 KB Output is correct
18 Correct 764 ms 53240 KB Output is correct
19 Correct 784 ms 50136 KB Output is correct
20 Correct 967 ms 51832 KB Output is correct
21 Correct 1078 ms 55032 KB Output is correct
22 Correct 1112 ms 55432 KB Output is correct
23 Correct 993 ms 54264 KB Output is correct
24 Correct 953 ms 54112 KB Output is correct
25 Correct 1239 ms 56080 KB Output is correct
26 Correct 1050 ms 54544 KB Output is correct
27 Correct 1012 ms 54520 KB Output is correct
28 Correct 919 ms 57080 KB Output is correct
29 Correct 901 ms 53240 KB Output is correct
30 Correct 1166 ms 55160 KB Output is correct
31 Correct 1127 ms 55160 KB Output is correct
32 Correct 984 ms 55088 KB Output is correct
33 Correct 952 ms 54008 KB Output is correct
34 Correct 987 ms 54136 KB Output is correct
35 Correct 1012 ms 54648 KB Output is correct
36 Correct 800 ms 53064 KB Output is correct
37 Correct 1034 ms 55160 KB Output is correct
38 Correct 901 ms 53112 KB Output is correct
39 Correct 1063 ms 54648 KB Output is correct
40 Correct 987 ms 54008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 25592 KB Output is correct
2 Correct 437 ms 25720 KB Output is correct
3 Correct 393 ms 25648 KB Output is correct
4 Correct 449 ms 25720 KB Output is correct
5 Correct 431 ms 25600 KB Output is correct
6 Correct 461 ms 25720 KB Output is correct
7 Correct 476 ms 25592 KB Output is correct
8 Correct 429 ms 25720 KB Output is correct
9 Correct 444 ms 25720 KB Output is correct
10 Correct 396 ms 25720 KB Output is correct
11 Incorrect 765 ms 28696 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 438 ms 25592 KB Output is correct
2 Correct 437 ms 25720 KB Output is correct
3 Correct 393 ms 25648 KB Output is correct
4 Correct 449 ms 25720 KB Output is correct
5 Correct 431 ms 25600 KB Output is correct
6 Correct 461 ms 25720 KB Output is correct
7 Correct 476 ms 25592 KB Output is correct
8 Correct 429 ms 25720 KB Output is correct
9 Correct 444 ms 25720 KB Output is correct
10 Correct 396 ms 25720 KB Output is correct
11 Correct 921 ms 52088 KB Output is correct
12 Correct 1079 ms 51704 KB Output is correct
13 Correct 982 ms 50936 KB Output is correct
14 Correct 914 ms 51192 KB Output is correct
15 Correct 1069 ms 52092 KB Output is correct
16 Correct 926 ms 51320 KB Output is correct
17 Correct 906 ms 51240 KB Output is correct
18 Correct 764 ms 53240 KB Output is correct
19 Correct 784 ms 50136 KB Output is correct
20 Correct 967 ms 51832 KB Output is correct
21 Correct 1078 ms 55032 KB Output is correct
22 Correct 1112 ms 55432 KB Output is correct
23 Correct 993 ms 54264 KB Output is correct
24 Correct 953 ms 54112 KB Output is correct
25 Correct 1239 ms 56080 KB Output is correct
26 Correct 1050 ms 54544 KB Output is correct
27 Correct 1012 ms 54520 KB Output is correct
28 Correct 919 ms 57080 KB Output is correct
29 Correct 901 ms 53240 KB Output is correct
30 Correct 1166 ms 55160 KB Output is correct
31 Correct 1127 ms 55160 KB Output is correct
32 Correct 984 ms 55088 KB Output is correct
33 Correct 952 ms 54008 KB Output is correct
34 Correct 987 ms 54136 KB Output is correct
35 Correct 1012 ms 54648 KB Output is correct
36 Correct 800 ms 53064 KB Output is correct
37 Correct 1034 ms 55160 KB Output is correct
38 Correct 901 ms 53112 KB Output is correct
39 Correct 1063 ms 54648 KB Output is correct
40 Correct 987 ms 54008 KB Output is correct
41 Incorrect 765 ms 28696 KB Output isn't correct
42 Halted 0 ms 0 KB -