Submission #496385

#TimeUsernameProblemLanguageResultExecution timeMemory
496385XBoRickiePIN (CEOI10_pin)C++14
100 / 100
140 ms18560 KiB
#include <bits/stdc++.h> using namespace std; // Typedef typedef long double ld; typedef long long int int64; typedef unsigned long long int uint64; typedef std::pair<int, int> PII; typedef std::pair<int64, int64> PLL; typedef std::vector<int> VI; typedef std::vector<long long> VLL; // Define For-loop #define FOR(i, j, k, in) for (int i = (j); i < (k) ; i += (in)) #define FORW(i, j, k, in) for (int i = (j); i <= (k); i += (in)) #define RFOR(i, j, k, in) for (int i = (j); i >= (k); i -= (in)) // Define Data structure func #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.rbegin(), cont.rend() #define sz(cont) int((cont).size()) #define pb push_back #define mp make_pair #define fi first #define se second // Define number #define IINF 0x3f3f3f3f #define LLINF 1000111000111000111LL #define PI 3.1415926535897932384626433832795 // Other #define lend '\n' #define hardio(name) freopen(name".inp","r",stdin), freopen(name".out","w",stdout); void FastIO() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); cin.exceptions(cin.failbit); srand(time(NULL)); } const int N = 5e5 + 6, base = 331, LG = (1 << 4) - 1; const int MOD = 1e9 + 7, MOD2 = 1e9 + 9; // ====================================================================== int n, d; map<int, int> hsh; int cnt[56] = {}; int64 val[6] = {}; string s[N] = {}; /* abcd => 4: abcd = 1 => 3: abc abd acd bcd = 4 => 2: ab ac ad bc bd cb = 6 => 1: a b c d = 4 ====================== We can see the answer will be overlapping: + With 3 characters, there'll be 4C3 way to abstract [choose 4] + With 2 characters, there'll be 4C2 way to abstract [choose 4], 3C2 way to abstract [choose 3] + With 1 characters, there'll be 4C1 way to abstract [choose 4], 3C1 way to abstract [choose 3], 2C1 way to abstract [choose 2] + With 0 characters, 4C0 + 3C0 + 2C0 + 1C0 */ int main(int argc, char* argv[]) { FastIO(); cin >> n >> d; FORW(i, 1, n, 1) { cin >> s[i]; s[i] = '$' + s[i]; } FORW(i, 1, LG, 1) cnt[i] = cnt[i >> 1] + (i & 1); FORW(mask, 0, LG, 1) { hsh.clear(); FORW(i, 1, n, 1) { int sum = 0; FORW(k, 1, 4, 1) sum = sum * base + ((mask >> (k - 1)) & 1 ? s[i][k] : 1); val[cnt[mask]] += hsh[sum]; hsh[sum]++; } } val[3] -= 4 * val[4]; val[2] -= 6 * val[4] + 3 * val[3]; val[1] -= 4 * val[4] + 3 * val[3] + 2 * val[2]; val[0] -= val[1] + val[2] + val[3] + val[4]; cout << val[4 - d] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...