답안 #238956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238956 2020-06-13T18:45:32 Z dolphingarlic PIN (CEOI10_pin) C++14
90 / 100
494 ms 14604 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

map<string, ll> cnt[16];
ll ans[5];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, d;
    cin >> n >> d;
    FOR(i, 0, n) {
        string s;
        cin >> s;
        FOR(j, 0, 16) {
            string sub = "";
            FOR(k, 0, 4) if (j & (1 << k)) sub += s[k];
            cnt[j][sub]++;
        }
    }

    FOR(i, 0, 16) {
        ll contrib = 0;
        for (pair<string, ll> j : cnt[i])
            contrib += j.second * (j.second - 1) / 2;
        ans[4 - __builtin_popcount(i)] += contrib;
    }
    
    if (d == 1) cout << ans[1] - ans[0];
    else if (d == 2) cout << ans[2] - 3 * (ans[1] - ans[0]);
    else if (d == 3) cout << ans[3] - 3 * (ans[2] + ans[1] - ans[0]);
    else cout << ans[4] - ans[3] + ans[2] - ans[1] + ans[0];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1024 KB Output is correct
2 Correct 10 ms 1024 KB Output is correct
3 Correct 9 ms 896 KB Output is correct
4 Correct 73 ms 3320 KB Output is correct
5 Correct 102 ms 3704 KB Output is correct
6 Correct 84 ms 3704 KB Output is correct
7 Correct 71 ms 3320 KB Output is correct
8 Correct 92 ms 3832 KB Output is correct
9 Correct 168 ms 5244 KB Output is correct
10 Correct 214 ms 5624 KB Output is correct
11 Correct 99 ms 3832 KB Output is correct
12 Incorrect 172 ms 5472 KB Output isn't correct
13 Incorrect 109 ms 4216 KB Output isn't correct
14 Correct 93 ms 3832 KB Output is correct
15 Correct 156 ms 5496 KB Output is correct
16 Correct 224 ms 11128 KB Output is correct
17 Correct 494 ms 14604 KB Output is correct
18 Correct 223 ms 12152 KB Output is correct
19 Correct 264 ms 13432 KB Output is correct
20 Correct 393 ms 14540 KB Output is correct