답안 #496460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496460 2021-12-21T08:37:57 Z LptN21 PIN (CEOI10_pin) C++14
100 / 100
27 ms 15724 KB
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
/* CODE BELOW */
const int N = 5e4 + 7, M = 4;
const ll oo = 1e18 + 7;
const int MOD = 1e9 + 7;

int n, m, k, t;

const int BASE = 37;

int a[N][M];

const int MX = 1874161 + 7;

int cnt[MX], bit[MX];

int getv(char c) {
    if('0' <= c && c <= '9') return c - '0' + 1;
    return c - 'a' + 11;
}

signed main() {
    //freopen("test.inp", "r", stdin);
    //freopen("test.out", "w", stdout);
    //fastIO;
    scanf("%d%d\n", &n, &m); char ch[M];

    for(int i=1;i<=n;i++) {
        scanf("%s\n", &ch);
        for(int j=0;j<M;j++) {
            a[i][j] = getv(ch[j]);
        }
        for(int j=0;j<MASK(M);j++) {
            int hs = 0, _cnt = 0;
            for(int l=0;l<M;l++) {
                hs= hs*BASE + a[i][l]*BIT(j, l);
                _cnt+=BIT(j, l);
            }
            cnt[hs]++, bit[hs] = _cnt;
        }
    }

    ll ans[M+1]; memset(ans, 0, sizeof ans);
    for(int i=0;i<MX;i++) if(cnt[i]) {
        ans[bit[i]]+= 1LL*cnt[i]*(cnt[i]-1)/2;
    }

    ans[3]-= ans[4];
    ans[2]-= 3*ans[3] + 6*ans[4];
    ans[1]-= 2*ans[2] + 3*ans[3] + 4*ans[4];
    ans[0]-= ans[1] + ans[2] + ans[3] + ans[4];
    printf("%lld", ans[M-m]);

    return 0;
}

Compilation message

pin.cpp: In function 'int main()':
pin.cpp:54:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[4]' [-Wformat=]
   54 |         scanf("%s\n", &ch);
      |                ~^     ~~~
      |                 |     |
      |                 char* char (*)[4]
pin.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     scanf("%d%d\n", &n, &m); char ch[M];
      |     ~~~~~^~~~~~~~~~~~~~~~~~
pin.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         scanf("%s\n", &ch);
      |         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3404 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 4 ms 3276 KB Output is correct
4 Correct 10 ms 3744 KB Output is correct
5 Correct 11 ms 3800 KB Output is correct
6 Correct 10 ms 3788 KB Output is correct
7 Correct 9 ms 3660 KB Output is correct
8 Correct 11 ms 3788 KB Output is correct
9 Correct 15 ms 4044 KB Output is correct
10 Correct 18 ms 4172 KB Output is correct
11 Correct 11 ms 3812 KB Output is correct
12 Correct 16 ms 4184 KB Output is correct
13 Correct 11 ms 3788 KB Output is correct
14 Correct 12 ms 3788 KB Output is correct
15 Correct 15 ms 4172 KB Output is correct
16 Correct 25 ms 15436 KB Output is correct
17 Correct 26 ms 15632 KB Output is correct
18 Correct 25 ms 15436 KB Output is correct
19 Correct 25 ms 15640 KB Output is correct
20 Correct 27 ms 15724 KB Output is correct