记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 388.0 KiB
#2 Wrong Answer 2ms 376.0 KiB
#3 Wrong Answer 42ms 416.0 KiB
#4 Wrong Answer 44ms 420.0 KiB
#5 Wrong Answer 42ms 420.0 KiB
#6 Wrong Answer 42ms 420.0 KiB
#7 Wrong Answer 42ms 416.0 KiB
#8 Wrong Answer 42ms 420.0 KiB
#9 Wrong Answer 43ms 420.0 KiB
#10 Wrong Answer 42ms 324.0 KiB

代码

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> bitCount(32, 0); // Count of '1's at each bit position
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        for (int j = 0; j < 32; ++j) {
            if (x & (1 << j)) {
                bitCount[j]++;
            }
        }
    }
    
    long long result = 0;
    bool valid = true;
    for (int j = 31; j >= 0 && valid; --j) { // Start from the most significant bit
        if (bitCount[j] > 1) { // If there is more than one '1' at this bit position
            int ones = 0, zeros = 0;
            for (int k = 0; k < j; ++k) {
                if (bitCount[k] > n - bitCount[k]) { // Check if 1s are more than 0s in lower bits
                    ones++;
                } else {
                    zeros++;
                    if (zeros > ones) { // If 0s become more than 1s, then this pair cannot satisfy the condition
                        valid = false;
                        break;
                    }
                }
            }
            if (valid) {
                result += bitCount[j] * (bitCount[j] - 1) / 2; // Combination C(bitCount[j], 2)
            }
        }
    }
    
    cout << result << endl;
    return 0;
}

信息

递交者
类型
递交
题目
P1002 统计
语言
C++
递交时间
2024-09-10 19:32:18
评测时间
2024-09-10 19:32:18
评测机
分数
0
总耗时
347ms
峰值内存
420.0 KiB