# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199752 | Mercenary | Snake Escaping (JOI18_snake_escaping) | C++14 | 2081 ms | 19028 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = (1 << 20);
string s;
int n , q;
int dp[2][maxn];
int res , f , nf , tmp;
int cnt[3] , a[maxn];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> q >> s;
for(int i = 0 ; i < (1 << n) ; ++i){
dp[0][i] = dp[1][(1 << n) - 1 - i] = a[i] = s[i] - '0';
}
for(int i = 0 ; i < n ; ++i){
for(int j = (1 << n) - 1 ; j >= 0 ; --j){
if(j & (1 << i))dp[0][j ^ (1 << i)] += dp[0][j] , dp[1][j ^ (1 << i)] += dp[1][j] ;
}
}
// cout << dp[1][7];
while(q--){
cnt[0] = cnt[1] = cnt[2] = res = f = nf = 0;
cin >> s;
for(int i = 0 ; i < n ; ++i){
if(s[i] == '0')s[i] = 0;
else if(s[i] == '1')s[i] = 1;
else s[i] = 2;
cnt[s[i]] |= (1 << (n - i - 1));
}
tmp = min_element(cnt,cnt+3)-cnt;
int *dp = ::dp[tmp];
for(int i = cnt[tmp] ;; i = (i - 1) & cnt[tmp]){
if(tmp < 2){
if(__builtin_popcount(i) & 1)res -= dp[i | cnt[!tmp]];
else res += dp[i | cnt[!tmp]];
}else{
res += a[i | cnt[1]];
}
if(i == 0)break;
}
cout << res << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |