제출 #116028

#제출 시각아이디문제언어결과실행 시간메모리
116028oolimrySnake Escaping (JOI18_snake_escaping)C++14
0 / 100
63 ms65536 KiB
#include <bits/stdc++.h> using namespace std; int value[2000000]; int memo[6600][4100]; 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; }

컴파일 시 표준 에러 (stderr) 메시지

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:83:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < s.length();i++){
                   ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...