# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
116030 | 2019-06-10T08:49:33 Z | oolimry | Snake Escaping (JOI18_snake_escaping) | C++14 | 104 ms | 65536 KB |
#include <bits/stdc++.h> using namespace std; static int value[2000000]; static int memo[3000][3000]; int n , q; int tleft; int tostring(string s){ int v = 0; for(int i = 0;i < n - tleft;i++){ v *= 3; if(s[i] == '0') v++; else if(s[i] == '1') v += 2; } return v; } int dp(string s, int t){ int x = tostring(s); if(memo[x][t] != -1) return memo[x][t]; for(int i = 0;i < n - tleft;i++){ if(s[i] == '?'){ string s0 = s; string s1 = s; s0[i] = '0'; s1[i] = '1'; int ans = dp(s0,t) + dp(s1,t); //cout << s << " " << ans << "\n"; memo[x][t] = ans; return ans; } } int v = 0; for(int i = 0;i < n - tleft;i++){ v *= 2; if(s[i] == '1') v++; } v <<= tleft; v += t; //cout << s << " " << t << " " << v << "ffff\n"; memo[x][t] = value[v]; return value[v]; } vector<int> options; void genop(string s){ for(int i = 0;i < tleft;i++){ if(s[i] == '?'){ string s0 = s; string s1 = s; s0[i] = '0'; s1[i] = '1'; genop(s1); genop(s0); return; } } int v = 0; for(int i = 0;i < tleft;i++){ v <<= 1; if(s[i] == '1')v++; } options.push_back(v); } int main() { //freopen("i.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(0); for(int i = 0;i < 6600;i++){ for(int j = 0;j < 4100;j++){ memo[i][j] = -1; } } cin >> n >> q; string s; cin >> s; for(int i = 0;i < s.length();i++){ value[i] = s[i] - '0'; } int split = 8; tleft = max(0, n - split); for(int qq = 0;qq < q;qq++){ cin >> s; string s1 = ""; for(int i = 0;i < split;i++){ s1 += s[i]; } string s2 = ""; for(int i = split;i < n;i++){ s2 += s[i]; } //cout << s1 << " " << s2 << "\n"; int ans = 0; options.clear(); genop(s2); for(int ss : options){ //cout << ss << "\n"; ans += dp(s1,ss); } cout << ans << "\n"; //cout << dp(s) << "\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 65536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 65536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 65536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 65536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 104 ms | 65536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |