답안 #873405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873405 2023-11-15T02:58:06 Z garam1732 Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
3 ms 10332 KB
#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define bl " "
#define endl "\n"
#define all(v) v.begin(), v.end()
#define comp(v) v.erase(unique(all(v)), v.end())
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000100/5;
const int MOD = 1e9+7;

struct Query {
    string s; int x; ll v;
}qry[MAXN];

vector<int> v;
int ans[MAXN];

void solve(int s, int e, int l, int r, int x) {
    if(s > e) return;
    if(l == r) {
        for(int i = s; i <= e; i++) ans[qry[i].x] = v[l];
        return;
    }

    int a = s, mid = l+r>>1;
    for(a = s; a <= e; a++) {
        if(qry[a].s[x] != '0') break;
    }

    solve(s, a-1, l, mid, x+1);

    s = a;
    for(; a <= e; a++) {
        if(qry[a].s[x] != '1') break;
    }

    solve(s, a-1, mid+1, r, x+1);

    s = a;
    for(int i = l, j = mid+1; j <= r; i++, j++) v[i] += v[j];
    solve(s, e, l, mid, x+1);
    for(int i = l, j = mid+1; j <= r; i++, j++) v[i] -= v[j];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int l, q; cin >> l >> q; char x;
    for(int i = 0; i < (1<<l); i++) {
        cin >> x; v.push_back(x-'0');
    }

    int sz = 5;
    for(int i = 0; i < sz; i++) {
        int s = q*i/sz+1, e = q*(i+1)/sz;

        for(int j = s; j <= e; j++) {
            cin >> qry[j-s].s; qry[j-s].x = j-s;
        }

        for(int j = 0; j <= e-s; j++) {
            for(int k = 0; k < l; k++) {
                qry[j].v *= 3;
                if(qry[j].s[k] == '1') qry[j].v += 1;
                else if(qry[j].s[k] == '?') qry[j].v += 2;
            }
        }

        sort(qry, qry+e-s+1, [](Query &a, Query &b){return a.v<b.v;});

        solve(0, e-s, 0, (1<<l)-1, 0);

        for(int j = 0; j <= e-s; j++) cout << ans[j] << endl;
    }
}

Compilation message

snake_escaping.cpp: In function 'void solve(int, int, int, int, int)':
snake_escaping.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int a = s, mid = l+r>>1;
      |                      ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 10332 KB Output isn't correct
2 Halted 0 ms 0 KB -