QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769942 | #6611. United in Stormwind | daylight-et-al# | WA | 1ms | 3864kb | C++23 | 6.4kb | 2024-11-21 19:59:14 | 2024-11-21 19:59:15 |
Judging History
answer
// competitive-verifier: PROBLEM
#include <cassert>
#include <cstdint>
#include <utility>
namespace internal {
namespace floor_sum {
// @param m `1 <= m`
// @return x mod m
constexpr std::int64_t safe_mod(std::int64_t x, std::int64_t m) {
x %= m;
if (x < 0) x += m;
return x;
}
// @param n `n < 2^32`
// @param m `1 <= m < 2^32`
// @return sum_{i=0}^{n-1} floor((ai + b) / m) (mod 2^64)
std::uint64_t floor_sum_unsigned(std::uint64_t n, std::uint64_t m, std::uint64_t a,
std::uint64_t b) {
std::uint64_t ans = 0;
while (true) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
std::uint64_t y_max = a * n + b;
if (y_max < m) break;
// y_max < m * (n + 1)
// floor(y_max / m) <= n
n = (std::uint64_t)(y_max / m);
b = (std::uint64_t)(y_max % m);
std::swap(m, a);
}
return ans;
}
} // namespace floor_sum
} // namespace internal
/**
* @brief floor sum
*
* @param n
* @param m
* @param a
* @param b
* @retval std::int64_t sum[0 <= i < n]floor((a * i + b) / m)
*
* @see https://atcoder.github.io/ac-library/production/document_ja/math.html
*/
std::int64_t floor_sum(std::int64_t n, std::int64_t m, std::int64_t a, std::int64_t b) {
assert(0 <= n && n < (1LL << 32));
assert(1 <= m && m < (1LL << 32));
std::uint64_t ans = 0;
if (a < 0) {
std::uint64_t a2 = internal::floor_sum::safe_mod(a, m);
ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m);
a = a2;
}
if (b < 0) {
std::uint64_t b2 = internal::floor_sum::safe_mod(b, m);
ans -= 1ULL * n * ((b2 - b) / m);
b = b2;
}
return ans + internal::floor_sum::floor_sum_unsigned(n, m, a, b);
}
#ifdef ATCODER
#pragma GCC target("sse4.2,avx512f,avx512dq,avx512ifma,avx512cd,avx512bw,avx512vl,bmi2")
#endif
#pragma GCC optimize("Ofast,fast-math,unroll-all-loops")
#include <bits/stdc++.h>
#ifndef ATCODER
#pragma GCC target("sse4.2,avx2,bmi2")
#endif
template <class T, class U>
constexpr bool chmax(T &a, const U &b) {
return a < (T)b ? a = (T)b, true : false;
}
template <class T, class U>
constexpr bool chmin(T &a, const U &b) {
return (T)b < a ? a = (T)b, true : false;
}
constexpr std::int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr double EPS = 1e-7;
constexpr double PI = 3.14159265358979323846;
#define FOR(i, m, n) for (int i = (m); i < int(n); ++i)
#define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i)
#define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i)
#define rep(i, n) FOR (i, 0, n)
#define repn(i, n) FOR (i, 1, n + 1)
#define repr(i, n) FORR (i, n, 0)
#define repnr(i, n) FORR (i, n + 1, 1)
#define all(s) (s).begin(), (s).end()
struct Sonic {
Sonic() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout << std::fixed << std::setprecision(20);
}
constexpr void operator()() const {}
} sonic;
using namespace std;
using ll = std::int64_t;
using ld = long double;
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
return is >> p.first >> p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (T &i : v) is >> i;
return is;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '(' << p.first << ',' << p.second << ')';
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
for (auto it = v.begin(); it != v.end(); ++it) os << (it == v.begin() ? "" : " ") << *it;
return os;
}
template <class Head, class... Tail>
void co(Head &&head, Tail &&...tail) {
if constexpr (sizeof...(tail) == 0) std::cout << head << '\n';
else std::cout << head << ' ', co(std::forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head &&head, Tail &&...tail) {
if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n';
else std::cerr << head << ' ', ce(std::forward<Tail>(tail)...);
}
void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes\n" : "No\n"); }
void No(bool is_not_correct = true) { Yes(!is_not_correct); }
void YES(bool is_correct = true) { std::cout << (is_correct ? "YES\n" : "NO\n"); }
void NO(bool is_not_correct = true) { YES(!is_not_correct); }
void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; }
void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); }
template <typename T>
void fwt(vector<T>& f) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((j & i) == 0) {
T x = f[j], y = f[j | i];
f[j] = x + y, f[j | i] = x - y;
}
}
}
}
template <typename T>
void ifwt(vector<T>& f) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((j & i) == 0) {
T x = f[j], y = f[j | i];
f[j] = (x + y) / 2, f[j | i] = (x - y) / 2;
}
}
}
}
template <typename T>
void fzt(vector<T>& f) {
int n = f.size();
for (int i = 1; i < n; i <<= 1) {
for (int j = 0; j < n; j++) {
if ((j & i) == 0) {
f[j | i] += f[j];
// この場合上位集合の畳み込みになる
// 左辺と右辺を逆にすると下位集合の畳み込みになる
}
}
}
}
int main(void) {
int n, m, k;
cin >> n >> m >> k;
vector<string> s(n);
cin >> s;
vector<int> a(1 << m), b(1 << m);
rep (i, n) {
int x = 0, y = 0;
rep (j, m) {
if (s[i][j] == 'B') {
x |= 1 << j;
} else {
y |= 1 << j;
}
}
a[x] += 1, b[y] += 1;
}
fwt(a), fwt(b);
rep (i, 1 << m) a[i] *= b[i];
ifwt(a);
a[(1 << m) - 1] = 0;
// ce(a);
fzt(a);
a[0] = 0;
// ce(a);
int ans = 0;
rep (i, 1 << m) {
ans += a[i] / 2 >= k;
}
co(ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
input:
2 2 1 AA BB
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 2 1 AA AB
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3864kb
input:
5000 10 12302135 AABAAAABBA AAABAABBAB BAABABAAAB ABBAABBBBA BAAAAABAAB BABBAAAAAA BABBABABAB BBABBAAAAB BABBABBBBA AAAAAAABAA BBBBBAABBA BAABABBAAB BABAAABAAA AAAAABAABB BBABAABABB ABAABBABBA BBBAAABABA BAAABABBAB ABAAAAABAA AABBBBBBAA ABBABBABBA AABBBABBAB BAABBAAABB BAAABBBBBB ABABBAABBB BABBABBA...
output:
1
result:
wrong answer 1st numbers differ - expected: '300', found: '1'