Submission #496460

#TimeUsernameProblemLanguageResultExecution timeMemory
496460LptN21PIN (CEOI10_pin)C++14
100 / 100
27 ms15724 KiB
#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 (stderr)

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);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...