Submission #301050

#TimeUsernameProblemLanguageResultExecution timeMemory
301050evpipisPIN (CEOI10_pin)C++11
100 / 100
180 ms2944 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

const int len = 5e4+5;
int out[len], n, k;
char str[len][5];

int solve(int bit){
    map<string, int> mym;

    for (int i = 0; i < n; i++){
        string temp;
        for (int j = 0; j < 4; j++){
            if (bit&(1<<j)) temp.push_back('*');
            else temp.push_back(str[i][j]);
        }

        mym[temp]++;
    }

    int ans = 0;
    for (auto &it: mym)
        ans += (it.se * 1LL * (it.se-1))/2; //, cout << it.fi << " " << it.se << endl;

    //printf("solving bit = %d\n", bit);
    //printf("ans = %d\n", ans);
    return ans;
}

int main(){
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%s", &str[i]);

    int ans = 0;
    for (int bit = 1; bit < (1<<4); bit++){
        out[bit] = solve(bit);

        for (int sub = 1; sub < bit; sub++)
            if ((sub&bit) == sub)
                out[bit] -= out[sub];

        if (__builtin_popcount(bit) == k)
            ans += out[bit];
    }

    printf("%d\n", ans);
    return 0;
}

Compilation message (stderr)

pin.cpp: In function 'int main()':
pin.cpp:36:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[5]' [-Wformat=]
   36 |         scanf("%s", &str[i]);
      |                ~^   ~~~~~~~
      |                 |   |
      |                 |   char (*)[5]
      |                 char*
pin.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
pin.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         scanf("%s", &str[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...