답안 #889310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889310 2023-12-19T10:28:02 Z hariaakas646 Snake Escaping (JOI18_snake_escaping) C++14
0 / 100
3 ms 348 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
 
 
void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    // usaco();
    fastio();
    int l, q;
    cin >> l >> q;
    string str;
    cin >> str;

    vi mv(1<<l);

    frange(i, 1<<l) {
        mv[i] = str[i] - '0';
    }

    vi po3(l+1);
    po3[0] = 1;
    forr(i, 1, l+1) po3[i] = po3[i-1] * 3;

    vector<string> quer(q);

    frange(i, q) {
        cin >> quer[i];
        reverse(all(quer[i]));
    }

    int v1 = min(l, 7);
    vi out(q);
    frange(i, 1<<v1) {
        vi val;
        frange(j, 1<<l) {
            if((j & i) == i) val.pb(mv[j]);
        }

        int v = 1;
        frange(i, l-v1) v *= 3;

        vi tot(v);

        frange(i, v) {
            int li=0;
            int r = 0;
            int x = 0;
            int k = i;
            bool done = false;
            frange(j, l-v1) {
                if(k % 3 == 1) {
                    x += po3[j];
                    li += po3[j];
                    r += po3[j];
                }
                else if(k % 3 == 2) {
                    x += po3[j] * 2;
                    if(!done)
                        {r += po3[j]; done = true;}
                    else {
                        li += po3[j] * 2;;
                        r += po3[j] * 2;
                    }
                }
                k /= 3;
            }
            k = i;
            if(!done) {
                int x2 = 0;
                frange(j, l) {
                    if(k % 3 == 1) {
                        x2 += (1<<j);
                    }
                    k /= 3;
                }
                tot[x] = val[x2];
            }
            else {
                // cout << x << " " << li << " " << r << "\n";
                tot[x] = tot[li] + tot[r];
            }
        }

        frange(k, q) {
            auto st = quer[k];
            bool done = true;
            frange(j, v1) {
                if(st[j] == '?') continue;
                int dig = st[j] - '0';
                if(dig != (bool)(i&(1<<j))) {
                    done = false;
                    break;
                }
            }
            if(done) {
                int num = 0;
                frange(j, l-v1) {
                    if(st[v1+j] == '1') v += po3[j];
                    else if(st[v1+j] == '?') v += 2*po3[j];
                }
                out[k] += tot[num];
            }
        }
    }

    frange(i, q) cout << out[i] << "\n";
}

Compilation message

snake_escaping.cpp: In function 'void usaco()':
snake_escaping.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -