# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
160791 | combi1k1 | Dango Maker (JOI18_dango_maker) | C++14 | 2 ms | 376 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int8_t c[1 << 20];
string s;
int f0[1 << 20];
int f1[1 << 20];
int work() {
int m0 = 0;
int m1 = 0;
int m2 = 0;
int L = s.size();
reverse(s.begin(),s.end());
for(int i = 0 ; i < L ; ++i) {
if (s[i] == '0') m0 |= (1 << i);
if (s[i] == '1') m1 |= (1 << i);
if (s[i] == '?') m2 |= (1 << i);
}
if (__builtin_popcount(m0) <= L / 3) {
int ans = f1[m1];
for(int x = m0 ; x ; x = (x - 1) & m0) {
if (__builtin_popcount(x) & 1)
ans -= f1[m1 | x];
else
ans += f1[m1 | x];
}
return ans;
}
if (__builtin_popcount(m1) <= L / 3) {
int ans = f0[m0];
for(int x = m1 ; x ; x = (x - 1) & m1) {
if (__builtin_popcount(x) & 1)
ans -= f0[m0 | x];
else
ans += f0[m0 | x];
}
return ans;
}
if (__builtin_popcount(m2) <= L / 3) {
int ans = c[m1];
for(int x = m2 ; x ; x = (x - 1) & m2)
ans += c[m1 | x];
return ans;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int q; cin >> q;
int m = (1 << n);
cin >> s;
for(int i = 0 ; i < m ; ++i)
f0[m - i - 1] = f1[i] = c[i] = s[i] - '0';
for(int i = 0 ; i < n ; ++i)
for(int j = 0 ; j < m ; ++j) if (j >> i & 1)
f0[j ^ (1 << i)] += f0[j],
f1[j ^ (1 << i)] += f1[j];
for(int i = 0 ; i < q ; ++i) {
cin >> s;
cout << work() << "\n";
}
}
/*
4 8
3141592653589793
0101
?01?
??1?
?0??
1?00
01?1
??10
????
*/
컴파일 시 표준 에러 (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... |