QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#297543 | #6309. Aqre | peaneval_kala | WA | 504ms | 3816kb | C++20 | 9.1kb | 2024-01-04 18:25:54 | 2024-01-04 18:25:54 |
Judging History
answer
#pragma GCC optimize(3, "unroll-loops", "no-stack-protector")
#define atsum(l, r) accumulate(l, r, 0)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 0x3f3f3f3f;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
inline void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
inline void chkmax(T &x, T y) {
x = max(x, y);
}
namespace FastIO {
// ------------------------------
#define IN_HAS_NEG
#define OUT_HAS_NEG
#define CHK_EOF
#define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if (defined(LOCAL) || defined(_WIN32)) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include <sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr,
*_read_ptr_end = nullptr;
inline char gc() {
if (__builtin_expect(_read_ptr == _read_ptr_end, false)) {
_read_ptr = _read_buffer;
_read_ptr_end =
_read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
if (__builtin_expect(_read_ptr == _read_ptr_end, false)) return EOF;
#endif
}
return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr =
(const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c) {
*_write_ptr++ = c;
if (__builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false)) {
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
_write_ptr = _write_buffer;
}
}
INLINE_V struct _auto_flush {
~_auto_flush() {
fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
}
} _auto_flush;
#endif
#ifdef CHK_EOF
inline bool _isdigit(char c) { return (c & 16) && c != EOF; }
inline bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline bool _isdigit(char c) { return c & 16; }
inline bool _isgraph(char c) { return c > 32; }
#endif
template <class T>
INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <class T>
INLINE_V constexpr bool _is_signed = numeric_limits<T>::is_signed;
template <class T>
INLINE_V constexpr bool _is_unsigned = _is_integer<T> && !_is_signed<T>;
template <>
INLINE_V constexpr bool _is_integer<__int128> = true;
template <>
INLINE_V constexpr bool _is_integer<__uint128_t> = true;
template <>
INLINE_V constexpr bool _is_signed<__int128> = true;
template <>
INLINE_V constexpr bool _is_unsigned<__uint128_t> = true;
#undef INLINE_V
inline void read(char &c) {
do c = gc();
while (!_isgraph(c));
}
inline void read_cstr(char *s) {
char c = gc();
while (!_isgraph(c)) c = gc();
while (_isgraph(c)) *s++ = c, c = gc();
*s = 0;
}
inline void read(string &s) {
char c = gc();
s.clear();
while (!_isgraph(c)) c = gc();
while (_isgraph(c)) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void read(T &x) {
char c = gc();
bool f = true;
x = 0;
while (!_isdigit(c)) {
if (c == 45) f = false;
c = gc();
}
if (f)
while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
else
while (_isdigit(c)) x = x * 10 - (c & 15), c = gc();
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void read(T &x) {
char c = gc();
while (!_isdigit(c)) c = gc();
x = 0;
while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) {
while (*s) pc(*s++);
}
inline void write(const string &s) {
for (char c : s) pc(c);
}
#ifdef OUT_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void write(T x) {
char buffer[numeric_limits<T>::digits10 + 1];
int digits = 0;
if (x >= 0) do
buffer[digits++] = (x % 10) | 48, x /= 10;
while (x);
else {
pc(45);
do buffer[digits++] = -(x % 10) | 48, x /= 10;
while (x);
}
while (digits) pc(buffer[--digits]);
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void write(T x) {
char buffer[numeric_limits<T>::digits10 + 1];
int digits = 0;
do buffer[digits++] = (x % 10) | 48, x /= 10;
while (x);
while (digits) pc(buffer[--digits]);
}
template <int N>
struct _tuple_io_helper {
template <class... T>
static inline void _read(tuple<T...> &x) {
_tuple_io_helper<N - 1>::_read(x), read(get<N - 1>(x));
}
template <class... T>
static inline void _write(const tuple<T...> &x) {
_tuple_io_helper<N - 1>::_write(x), pc(32), write(get<N - 1>(x));
}
};
template <>
struct _tuple_io_helper<1> {
template <class... T>
static inline void _read(tuple<T...> &x) {
read(get<0>(x));
}
template <class... T>
static inline void _write(const tuple<T...> &x) {
write(get<0>(x));
}
};
template <class... T>
inline void read(tuple<T...> &x) {
_tuple_io_helper<sizeof...(T)>::_read(x);
}
template <class... T>
inline void write(const tuple<T...> &x) {
_tuple_io_helper<sizeof...(T)>::_write(x);
}
template <class T1, class T2>
inline void read(pair<T1, T2> &x) {
read(x.first), read(x.second);
}
template <class T1, class T2>
inline void write(const pair<T1, T2> &x) {
write(x.first), pc(32), write(x.second);
}
template <class T1, class... T2>
inline void read(T1 &x, T2 &...y) {
read(x), read(y...);
}
template <class... T>
inline void read_cstr(char *x, T *...y) {
read_cstr(x), read_cstr(y...);
}
template <class T1, class... T2>
inline void write(const T1 &x, const T2 &...y) {
write(x), write(y...);
}
template <class... T>
inline void write_cstr(const char *x, const T *...y) {
write_cstr(x), write_cstr(y...);
}
template <class T>
inline void print(const T &x) {
write(x);
}
inline void print_cstr(const char *x) { write_cstr(x); }
template <class T1, class... T2>
inline void print(const T1 &x, const T2 &...y) {
print(x), pc(32), print(y...);
}
template <class... T>
inline void print_cstr(const char *x, const T *...y) {
print_cstr(x), pc(32), print_cstr(y...);
}
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template <class... T>
inline void println(const T &...x) {
print(x...), pc(10);
}
template <class... T>
inline void println_cstr(const T *...x) {
print_cstr(x...), pc(10);
}
} // namespace FastIO
using namespace FastIO;
template <typename T>
inline void clear(T &x) {
T y;
swap(x, y);
}
const int N = 1e3 + 10;
int ans = 0, ca;
int a[N][N];
inline int sprint(int c, int n, int m) {
int res = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
res += a[i][j] = bool(c & (1 << (((i & 3) << 2) | (j & 3))));
return res;
}
int cn, cm, n, m;
int cc = 0;
inline void flood(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= m) return;
if (a[x][y])
a[x][y] = 0, ++cc;
else
return;
flood(x - 1, y), flood(x + 1, y);
flood(x, y - 1), flood(x, y + 1);
}
inline int check(int c) {
int p = sprint(c, n, m);
for (int i = 0; i + 3 < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j] && a[i + 1][j] && a[i + 2][j] && a[i + 3][j]) return 0;
for (int i = 0; i < n; i++)
for (int j = 0; j + 3 < m; j++)
if (a[i][j] && a[i][j + 1] && a[i][j + 2] && a[i][j + 3]) return 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (a[i][j]) {
cc = 0;
flood(i, j);
if (cc != p) return 0;
break;
}
return p;
}
int res[8][8];
inline void work() {
ca = ans = 0;
read(cn, cm);
n = cn, m = cm;
while (n > 8) n -= 4;
while (m > 8) m -= 4;
if (!res[n][m]) {
for (int i = 1; i < (1 << 16); i++) {
int p = check(i);
if (p > ans) ans = p, ca = i;
}
res[n][m] = ca;
}
ca = res[n][m];
// cerr << "ans:" << ans << ' '<< ca << ' ' << cn << ' ' << cm << endl;
int c = sprint(ca, cn, cm);
println(c);
for (int i = 0; i < cn; i++) {
for (int j = 0; j < cm; j++) write(a[i][j]), a[i][j] = 0;
println();
}
}
int main() {
int T;
read(T);
while (T--) work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 3584kb
input:
3 2 2 3 4 3 8
output:
4 11 11 9 1110 1110 1110 18 10111011 11101110 11101110
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 504ms
memory: 3816kb
input:
361 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 4 2 4 3 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 5 1...
output:
4 11 11 6 111 111 6 1110 1110 8 10111 11101 9 101110 111011 11 1011101 1110111 12 10111011 11101110 14 101110111 111011101 15 1011101110 1110111011 17 10111011101 11101110111 18 101110111011 111011101110 20 1011101110111 1110111011101 21 10111011101110 11101110111011 23 101110111011101 1110111011101...
result:
wrong answer (0, 1) to (3, 1) are the same (test case 102)