Submission #970531

# Submission time Handle Problem Language Result Execution time Memory
970531 2024-04-26T16:38:46 Z mychecksedad Snake Escaping (JOI18_snake_escaping) C++17
12 / 100
424 ms 65540 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2e6+100, M = 1e5+10, K = 13, MX = 30;

int n, q, cost[N], dp[N], p[15];
short int val[N][K];
string s;
void solve(){
  cin >> n >> q >> s;
  if(n > 13) return;
  for(int i = 0; i < N; ++i) dp[i] = 0;
  for(int i = 0; i < (1<<n); ++i){
    int val = 0;
    for(int j =0 ; j < n; ++j){
      if((1<<j)&i) val += 2*p[j];
      else val += p[j];
    }
    dp[val] += s[i] - '0';
  }

  // for(int i = 0; i < p[n]; ++i){
  //   cout << i << ": "; for(int j = 0; j < 5; ++j) cout << val[i][j];
  //   en;
  // }

  for(int i = 0; i < n; ++i){
    for(int mask = 0; mask < p[n]; ++mask){
      if(val[mask][i] == 0){
        dp[mask] += dp[mask + p[i]];
        dp[mask] += dp[mask + 2*p[i]];
      }
    }
  }

  for(int i = 0; i < q; ++i){
    string t; cin >> t;
    int val = 0;
    for(int j = 0; j < n; ++j){
      if(t[n - j - 1] == '0') val += p[j];
      else if(t[n - j - 1] == '1') val += p[j] * 2;
    }
    cout << dp[val] << '\n';
  }
}



int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  p[0] = 1;
  for(int i = 1; i <15; ++i) p[i] = p[i - 1] * 3;
  for(int i = 0; i < N; ++i){
    int x = i;
    for(int j = 0; j < K; ++j){
      val[i][j] = x % 3;
      x /= 3;
    }
  }
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    // en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:57:15: warning: unused variable 'aa' [-Wunused-variable]
   57 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 41 ms 58964 KB Output is correct
2 Correct 32 ms 59076 KB Output is correct
3 Correct 31 ms 59032 KB Output is correct
4 Correct 31 ms 59996 KB Output is correct
5 Correct 30 ms 60064 KB Output is correct
6 Correct 31 ms 59988 KB Output is correct
7 Correct 31 ms 59992 KB Output is correct
8 Correct 31 ms 60104 KB Output is correct
9 Correct 31 ms 59988 KB Output is correct
10 Correct 30 ms 59988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 58964 KB Output is correct
2 Correct 32 ms 59076 KB Output is correct
3 Correct 31 ms 59032 KB Output is correct
4 Correct 31 ms 59996 KB Output is correct
5 Correct 30 ms 60064 KB Output is correct
6 Correct 31 ms 59988 KB Output is correct
7 Correct 31 ms 59992 KB Output is correct
8 Correct 31 ms 60104 KB Output is correct
9 Correct 31 ms 59988 KB Output is correct
10 Correct 30 ms 59988 KB Output is correct
11 Correct 195 ms 65536 KB Output is correct
12 Correct 201 ms 65536 KB Output is correct
13 Correct 214 ms 65536 KB Output is correct
14 Correct 215 ms 65536 KB Output is correct
15 Correct 203 ms 65536 KB Output is correct
16 Correct 222 ms 65536 KB Output is correct
17 Correct 223 ms 65536 KB Output is correct
18 Correct 168 ms 65536 KB Output is correct
19 Correct 189 ms 65536 KB Output is correct
20 Correct 207 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 58964 KB Output is correct
2 Correct 32 ms 59076 KB Output is correct
3 Correct 31 ms 59032 KB Output is correct
4 Correct 31 ms 59996 KB Output is correct
5 Correct 30 ms 60064 KB Output is correct
6 Correct 31 ms 59988 KB Output is correct
7 Correct 31 ms 59992 KB Output is correct
8 Correct 31 ms 60104 KB Output is correct
9 Correct 31 ms 59988 KB Output is correct
10 Correct 30 ms 59988 KB Output is correct
11 Correct 195 ms 65536 KB Output is correct
12 Correct 201 ms 65536 KB Output is correct
13 Correct 214 ms 65536 KB Output is correct
14 Correct 215 ms 65536 KB Output is correct
15 Correct 203 ms 65536 KB Output is correct
16 Correct 222 ms 65536 KB Output is correct
17 Correct 223 ms 65536 KB Output is correct
18 Correct 168 ms 65536 KB Output is correct
19 Correct 189 ms 65536 KB Output is correct
20 Correct 207 ms 65536 KB Output is correct
21 Correct 266 ms 65536 KB Output is correct
22 Correct 279 ms 65536 KB Output is correct
23 Correct 294 ms 65536 KB Output is correct
24 Correct 284 ms 65536 KB Output is correct
25 Correct 274 ms 65536 KB Output is correct
26 Correct 296 ms 65536 KB Output is correct
27 Correct 314 ms 65536 KB Output is correct
28 Runtime error 424 ms 65540 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 58964 KB Output is correct
2 Correct 32 ms 59076 KB Output is correct
3 Correct 31 ms 59032 KB Output is correct
4 Correct 31 ms 59996 KB Output is correct
5 Correct 30 ms 60064 KB Output is correct
6 Correct 31 ms 59988 KB Output is correct
7 Correct 31 ms 59992 KB Output is correct
8 Correct 31 ms 60104 KB Output is correct
9 Correct 31 ms 59988 KB Output is correct
10 Correct 30 ms 59988 KB Output is correct
11 Incorrect 29 ms 55276 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 58964 KB Output is correct
2 Correct 32 ms 59076 KB Output is correct
3 Correct 31 ms 59032 KB Output is correct
4 Correct 31 ms 59996 KB Output is correct
5 Correct 30 ms 60064 KB Output is correct
6 Correct 31 ms 59988 KB Output is correct
7 Correct 31 ms 59992 KB Output is correct
8 Correct 31 ms 60104 KB Output is correct
9 Correct 31 ms 59988 KB Output is correct
10 Correct 30 ms 59988 KB Output is correct
11 Correct 195 ms 65536 KB Output is correct
12 Correct 201 ms 65536 KB Output is correct
13 Correct 214 ms 65536 KB Output is correct
14 Correct 215 ms 65536 KB Output is correct
15 Correct 203 ms 65536 KB Output is correct
16 Correct 222 ms 65536 KB Output is correct
17 Correct 223 ms 65536 KB Output is correct
18 Correct 168 ms 65536 KB Output is correct
19 Correct 189 ms 65536 KB Output is correct
20 Correct 207 ms 65536 KB Output is correct
21 Correct 266 ms 65536 KB Output is correct
22 Correct 279 ms 65536 KB Output is correct
23 Correct 294 ms 65536 KB Output is correct
24 Correct 284 ms 65536 KB Output is correct
25 Correct 274 ms 65536 KB Output is correct
26 Correct 296 ms 65536 KB Output is correct
27 Correct 314 ms 65536 KB Output is correct
28 Runtime error 424 ms 65540 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -