QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506375#4912. WereYouLastlifanCompile Error//C++142.9kb2024-08-05 16:59:372024-08-05 16:59:37

Judging History

你现在查看的是最新测评结果

  • [2024-08-05 16:59:37]
  • 评测
  • [2024-08-05 16:59:37]
  • 提交

answer

// 
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 20 + 5;
char iron[1 << 20] , T[MAXN];
int n , m , q , pre1[1 << 20] , pre2[1 << 20] , S , ans;
// ? 永远视为 1
// 1 和 ? 组合就视为 0
// 0 和 ? 组合就视为 0
void dfs0(int u , int stu , int f) {
    if (u == m + 1) {
        ans += pre2[stu] * f;
        return;
    }
    if (T[u] == '?') dfs0(u + 1 , stu | (1 << u - 1) , f);
    else if (T[u] == '1') dfs0(u + 1 , stu , f);
    else {
        dfs0(u + 1 , stu | (1 << u - 1) , f);
        dfs0(u + 1 , stu , -f);
    }
}
void dfs1(int u , int stu , int f) {
    if (u == m + 1) {
        ans += pre1[stu] * f;
        return;
    }
    if (T[u] == '?') dfs1(u + 1 , stu | (1 << u - 1) , f);
    else if (T[u] == '0') dfs1(u + 1 , stu , f);
    else {
        dfs1(u + 1 , stu | (1 << u - 1) , f);
        dfs1(u + 1 , stu , -f);
    }
}
void dfs2(int u , int stu) {
    if (u == m + 1) {
        ans += (iron[stu] ^ 48);
        return;
    }
    if (T[u] == '1') dfs2(u + 1 , stu | (1 << u - 1));
    else if (T[u] == '0') dfs2(u + 1 , stu);
    else {
        dfs2(u + 1 , stu | (1 << u - 1));
        dfs2(u + 1 , stu);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr) , cout.tie(nullptr);
    cin >> n >> q;
    S = (1 << n) - 1;
    cin >> iron;
    for (int i = 0 ; i < (1 << n) ; i ++) pre1[i] = pre2[i ^ S] = (iron[i] ^ 48);
    for(int i = 0 ; i < n ; i ++) {
		for(int j = 0 ; j < (1 << n) ; j ++) {
			if(j & (1 << i)) pre1[j] += pre1[j ^ (1 << i)] , pre2[j] += pre2[j ^ (1 << i)];
		}
	}
    while(q --) {
        cin >> (T + 1);
        m = strlen(T + 1);
        for (int i = 1 ; i <= m / 2 ; i ++) swap(T[i] , T[m - i + 1]);
        int cnt0 = 0 , cnt1 = 0 , cnt2 = 0;
        for (int i = 1 ; i <= m ; i ++) cnt0 += (T[i] == '0') , cnt1 += (T[i] == '1') , cnt2 += (T[i] == '?');
        if (!cnt2) {
            int stu = 0;
            for (int i = 1 ; i <= m ; i ++) {
                if (T[i] == '1') stu |= (1 << i - 1);
            }
            cout << (iron[stu] ^ 48) << '\n';
            continue;
        }
        if (!cnt1) {
            int stu = 0;
            for (int i = 1 ; i <= m ; i ++) {
                if (T[i] == '?') stu |= (1 << i - 1);
            }
            cout << pre1[stu] << '\n';
            continue;
        }
        if (!cnt0) {
            int stu = 0;
            for (int i = 1 ; i <= m ; i ++) {
                if (T[i] == '?') stu |= (1 << i - 1);
            }
            cout << pre2[stu] << '\n';
            continue;
        }
        ans = 0;
        int Min = min({cnt0 , cnt1 , cnt2});
        if (Min == cnt0) {
            dfs0(1 , 0 , 1);
            cout << ans << '\n';
        } else if (Min == cnt1) {
            dfs1(1 , 0 , 1);
            cout << ans << '\n';
        } else {
            dfs2(1 , 0);
            cout << ans << '\n';
        }
    }
    return 0;
}

詳細信息

/usr/bin/ld: /tmp/ccFzJ8PE.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccJONKJD.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccJONKJD.o: in function `qWqautomaton::main1()':
implementer.cpp:(.text+0x270): undefined reference to `WereYouLast(int, int)'
/usr/bin/ld: /tmp/ccJONKJD.o: in function `qWqautomaton::main2()':
implementer.cpp:(.text+0x38a): undefined reference to `WereYouLast(int, int)'
collect2: error: ld returned 1 exit status