답안 #1001191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001191 2024-06-18T16:52:00 Z mispertion Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
528 ms 27884 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
 
const ld PI = 3.1415926535;
const int N = 1e6+10;
const int M = 7e6 + 1;
int mod = 1e9+7;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 2;
 
int mult(int a, int b) {
    return a * 1LL * b % mod;
}
 
int sum(int a, int b) { 
    if (a + b < 0)
        return a + b + mod;
    if (a + b >= mod)
        return a + b - mod;
    return a + b;
}
 
ll binpow(ll a, ll n) {
    if (n == 0)
        return 1;
    if (n % 2 == 1) {
        return binpow(a, n - 1) * a % mod;
    } else {
        ll b = binpow(a, n / 2);
        return b * b % mod;
    }
}
 
int n, q, a[N], sos[N], sou[N];

void solve(){
    cin >> n >> q;
    string tmp;
    cin >> tmp;
    for(int i = 0; i < (1 << n); i++)
        sos[i] = sou[i] = a[i] = tmp[i] - '0';
    //sum over subsets
    for(int i = 0; i < n; i++)
        for(int mask = 0; mask < (1 << n); mask++)
            if(mask & (1 << i))
                sos[mask] += sos[mask ^ (1 << i)];
    for(int i = 0; i < n; i++)
        for(int mask = (1 << n) - 1; mask >= 0; mask--)
            if(!(mask & (1 << i)))
                sou[mask] += sou[mask ^ (1 << i)];
    while(q--){
        vector<int> und = {}, zer = {}, one = {};
        string s;
        cin >> s;
        reverse(all(s));
        int mainm = 0, unmask = 0, zermask = 0;
        for(int i = 0; i < sz(s); i++){
            if(s[i] == '?')
                und.pb(i), unmask += (1 << i);
            if(s[i] == '0')
                zer.pb(i), zermask += (1 << i);
            if(s[i] == '1')
                one.pb(i), mainm += (1 << i);
        }
        if(sz(und) <= sz(zer) && sz(und) <= sz(one)){
            int ans = a[mainm];
            for(int mask = unmask; mask > 0; mask = (mask - 1) & unmask){
                ans += a[mask + mainm];
            }
            cout << ans << '\n';
        }else if(sz(zer) <= sz(und) && sz(one) >= sz(zer)){
            int ans = sou[mainm];
            for(int mask = zermask; mask > 0; mask = (mask - 1) & zermask){
                int cnt = __builtin_popcount(mask);
                if(cnt % 2)
                    ans -= sou[mask + mainm];
                else
                    ans += sou[mask + mainm];
            }
            cout << ans << '\n';
        }else{
            int ans = 0;
            if(sz(one) % 2)
                ans -= sos[unmask];
            else
                ans += sos[unmask];
            for(int mask = mainm; mask > 0; mask = (mask - 1) & mainm){
                int cnt = sz(one) - __builtin_popcount(mask);
                if(cnt % 2)
                    ans -= sos[mask + unmask];
                else
                    ans += sos[mask + unmask];
            }
            cout << ans << '\n';
        }
    }
}
 
signed main() {
    mispertion;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 312 ms 19148 KB Output is correct
12 Correct 301 ms 18772 KB Output is correct
13 Correct 348 ms 18192 KB Output is correct
14 Correct 349 ms 18260 KB Output is correct
15 Correct 345 ms 19236 KB Output is correct
16 Correct 369 ms 18400 KB Output is correct
17 Correct 420 ms 18260 KB Output is correct
18 Correct 203 ms 20308 KB Output is correct
19 Correct 290 ms 17236 KB Output is correct
20 Correct 295 ms 16948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 312 ms 19148 KB Output is correct
12 Correct 301 ms 18772 KB Output is correct
13 Correct 348 ms 18192 KB Output is correct
14 Correct 349 ms 18260 KB Output is correct
15 Correct 345 ms 19236 KB Output is correct
16 Correct 369 ms 18400 KB Output is correct
17 Correct 420 ms 18260 KB Output is correct
18 Correct 203 ms 20308 KB Output is correct
19 Correct 290 ms 17236 KB Output is correct
20 Correct 295 ms 16948 KB Output is correct
21 Correct 323 ms 22308 KB Output is correct
22 Correct 351 ms 22352 KB Output is correct
23 Correct 409 ms 21588 KB Output is correct
24 Correct 417 ms 21332 KB Output is correct
25 Correct 369 ms 23124 KB Output is correct
26 Correct 430 ms 21588 KB Output is correct
27 Correct 469 ms 21616 KB Output is correct
28 Correct 227 ms 24276 KB Output is correct
29 Correct 330 ms 20112 KB Output is correct
30 Correct 388 ms 22384 KB Output is correct
31 Correct 528 ms 22096 KB Output is correct
32 Correct 493 ms 22224 KB Output is correct
33 Correct 372 ms 21124 KB Output is correct
34 Correct 506 ms 21332 KB Output is correct
35 Correct 484 ms 21748 KB Output is correct
36 Correct 209 ms 20308 KB Output is correct
37 Correct 319 ms 22216 KB Output is correct
38 Correct 343 ms 20308 KB Output is correct
39 Correct 411 ms 19284 KB Output is correct
40 Correct 413 ms 19124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Runtime error 16 ms 27884 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 312 ms 19148 KB Output is correct
12 Correct 301 ms 18772 KB Output is correct
13 Correct 348 ms 18192 KB Output is correct
14 Correct 349 ms 18260 KB Output is correct
15 Correct 345 ms 19236 KB Output is correct
16 Correct 369 ms 18400 KB Output is correct
17 Correct 420 ms 18260 KB Output is correct
18 Correct 203 ms 20308 KB Output is correct
19 Correct 290 ms 17236 KB Output is correct
20 Correct 295 ms 16948 KB Output is correct
21 Correct 323 ms 22308 KB Output is correct
22 Correct 351 ms 22352 KB Output is correct
23 Correct 409 ms 21588 KB Output is correct
24 Correct 417 ms 21332 KB Output is correct
25 Correct 369 ms 23124 KB Output is correct
26 Correct 430 ms 21588 KB Output is correct
27 Correct 469 ms 21616 KB Output is correct
28 Correct 227 ms 24276 KB Output is correct
29 Correct 330 ms 20112 KB Output is correct
30 Correct 388 ms 22384 KB Output is correct
31 Correct 528 ms 22096 KB Output is correct
32 Correct 493 ms 22224 KB Output is correct
33 Correct 372 ms 21124 KB Output is correct
34 Correct 506 ms 21332 KB Output is correct
35 Correct 484 ms 21748 KB Output is correct
36 Correct 209 ms 20308 KB Output is correct
37 Correct 319 ms 22216 KB Output is correct
38 Correct 343 ms 20308 KB Output is correct
39 Correct 411 ms 19284 KB Output is correct
40 Correct 413 ms 19124 KB Output is correct
41 Runtime error 16 ms 27884 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -