이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |