Submission #1303103

#TimeUsernameProblemLanguageResultExecution timeMemory
1303103the_commando_xPIN (CEOI10_pin)C++17
90 / 100
22 ms4324 KiB
// #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; using vii = vector<pii>; using vvii = vector<vii>; using l = long long; using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>; using pll = pair<l, l>; using vll = vector<pll>; using vvll = vector<vll>; using d = double; using vd = vector<d>; using vvd = vector<vd>; using vvvd = vector<vvd>; using ld = long double; using vld = vector<ld>; using vvld = vector<vld>; using vvvld = vector<vvld>; using vb = vector<bool>; using vvb = vector<vb>; using pbb = pair<bool, bool>; using vbb = vector<pbb>; #define ff first #define ss second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (!name.empty()) { (void)freopen((name + ".in").c_str(), "r", stdin); (void)freopen((name + ".out").c_str(), "w", stdout); } } const ld pi = 3.14159265358979323846; const l LINF = 1e18; const l INF = 1e9; const l MOD = 1e9 + 7; // const l MOD = 998244353; const l MAXN = 2e5 + 5; l hashsubset(const string &s, int mask) { l res = 0; for (int bit = 0; bit < 4; ++bit) if (mask & (1 << bit)) { char c = s[bit]; res *= 36; if (isdigit(c)) res += c - '0'; else res += c - 'a' + 10; } return res; } void solve() { int N, D; cin >> N >> D; vector<string> a(N); for (auto &s : a) cin >> s; vl cnt(16, 0); // cnt[mask] for (int mask = 0; mask < 16; ++mask) { unordered_map<l, l> mp; // {key,cnt} mp.reserve(N * 2); for (int i = 0; i < N; ++i) { l key = hashsubset(a[i], mask); ++mp[key]; } l sum = 0; for (auto &[_, cnt] : mp) sum += ((cnt - 1) * cnt) / 2; cnt[mask] = sum; } vl totCnt(5, 0); for (int mask = 0; mask < 16; ++mask) totCnt[__builtin_popcount(mask)] += cnt[mask]; vl ans(5, 0); ans[4] = totCnt[4]; ans[3] = totCnt[3] - 4 * ans[4]; ans[2] = totCnt[2] - 3 * ans[3] - 6 * ans[4]; ans[1] = totCnt[1] - 2 * ans[2] - 3 * ans[3] - 4 * ans[4]; ans[0] = (N * (N - 1) / 2) - (ans[1] + ans[2] + ans[3] + ans[4]); cout << ans[4 - D]; } int main() { setIO(""); #ifndef ONLINE_JUDGE // setIO("filename"); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

pin.cpp: In function 'void setIO(std::string)':
pin.cpp:53:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         (void)freopen((name + ".in").c_str(), "r", stdin);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pin.cpp:54:22: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         (void)freopen((name + ".out").c_str(), "w", stdout);
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...