记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 420.0 KiB
#2 Wrong Answer 2ms 416.0 KiB
#3 Wrong Answer 42ms 420.0 KiB
#4 Wrong Answer 42ms 420.0 KiB
#5 Wrong Answer 42ms 424.0 KiB
#6 Wrong Answer 42ms 424.0 KiB
#7 Wrong Answer 42ms 412.0 KiB
#8 Wrong Answer 42ms 424.0 KiB
#9 Wrong Answer 46ms 420.0 KiB
#10 Wrong Answer 46ms 420.0 KiB

代码

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> bitCounts(32, 0); // To store the count of '1's for 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)) {
                bitCounts[j]++;
            }
        }
    }
    
    long long result = 0;
    for (int count : bitCounts) {
        // Combination formula: C(n, 2) = n * (n - 1) / 2
        if (count > 1) {
            result += count * (count - 1) / 2;
        }
    }
    
    cout << result << endl;
    return 0;
}

信息

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