QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#294252 | #4826. Find the Parts | ucup-team896# | 0 | 1ms | 3628kb | C++23 | 9.2kb | 2023-12-30 10:51:41 | 2023-12-30 10:51:42 |
answer
/*
* @Author: cmk666
* @Created time: 2023-12-30 09:52:11
* @Last Modified time: 2023-12-30 10:48:55
*/
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
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
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; }
inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline constexpr bool _isdigit(char c) { return c & 16; }
inline constexpr 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); }
}
using namespace FastIO;
string _;
constexpr int B = 1145, D = 29, M = ( 1 << D ) - 1;
int r, c, q, h, rr, cc, len, resx, resy, a[2009][2009];
deque < int > que; vector < int > ans; map < int, pair < int, int > > mp;
inline int in()
{
char c1, c2; read(c1, c2);
return ( ( c1 & 32 ? c1 - 48 : c1 - 55 ) << 4 ) | ( c2 & 32 ? c2 - 48 : c2 - 55 );
}
inline void out(int x) { write("0123456789ABCDEF"[x >> 4], "0123456789ABCDEF"[x & 15]); }
int main()
{
read(_);
if ( _ == "message" )
{
read(r, c);
For(i, 1, r) For(j, 1, c) a[i][j] = in();
ans.push_back(r >> 8), ans.push_back(r & 255);
ans.push_back(c >> 8), ans.push_back(c & 255);
for ( int i = 6 ; i + 6 <= r ; i += 6 ) for ( int j = 6 ; j + 6 <= c ; j += 6 )
{
h = 0;
For(ii, 0, 4) For(jj, 0, 4) h = ( (ll)h * B + a[i + ii][j + jj] ) & M;
Fol(ii, D - 1, 0) que.push_back(( h >> ii ) & 1);
while ( (int)que.size() > 7 )
{
ans.push_back(0);
For(ii, 0, 7) ans.back() = ( ans.back() << 1 ) | que.front(), que.pop_front();
}
}
if ( que.size() )
{
while ( (int)que.size() < 8 ) que.push_back(0);
ans.push_back(0);
For(ii, 0, 7) ans.back() = ( ans.back() << 1 ) | que.front(), que.pop_front();
}
len = (int)ans.size(), assert(len <= 409600), println(len);
for ( int i : ans ) out(i), write(--len ? ' ' : '\n');
}
else if ( _ == "parts" )
{
read(len);
r = in() << 8, r |= in(), c = in() << 8, c |= in();
For(i, 5, len) { h = in(); Fol(j, 7, 0) que.push_back(( h >> j ) & 1); }
for ( int i = 6 ; i + 6 <= r ; i += 6 ) for ( int j = 6 ; j + 6 <= c ; j += 6 )
{
h = 0;
For(ii, 0, D - 1) h = ( h << 1 ) | que.front(), que.pop_front();
mp[h] = pair(i, j);
}
read(q);
For(_, 1, q)
{
read(rr, cc), resx = resy = 0;
For(i, 1, rr) For(j, 1, cc) a[i][j] = in();
For(i, 1, rr - 4) For(j, 1, cc - 4)
{
h = 0;
For(ii, 0, 4) For(jj, 0, 4) h = ( (ll)h * B + a[i + ii][j + jj] ) & M;
if ( mp.count(h) ) { resx = mp[h].first - i + 1, resy = mp[h].second - j + 1; break; }
}
assert(resx && resy), println(resx, resy);
}
}
return 0;
}
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
message 20 24 33 39 73 4A 5A AA E0 86 96 4B 0B 83 A0 FA 82 9B B0 6E DC 03 1C B9 5B 81 86 3E 23 7B C9 38 77 82 7D 62 EA CE A8 DE 85 6C 36 B3 10 EE 85 6A D5 92 14 BD 58 74 20 7B 36 E1 89 B8 6F 4A F4 8F 17 2E 2F 0F 79 DD AA 9F 6F AD 85 21 B6 2F 58 37 87 7B 3F EE D9 7D 9A E6 AA 12 E0 B6 BB 3D 72 BD 34 A...
output:
26 00 14 00 18 3A 4B 49 E7 9B FF EC 7D 92 B1 3D FD 07 B1 FD 0D 61 5F 2C 02 91 68
input:
parts 26 00 14 00 18 3A 4B 49 E7 9B FF EC 7D 92 B1 3D FD 07 B1 FD 0D 61 5F 2C 02 91 68 2 10 10 39 73 4A 5A AA E0 86 96 4B 0B 3E 23 7B C9 38 77 82 7D 62 EA BD 58 74 20 7B 36 E1 89 B8 6F 21 B6 2F 58 37 87 7B 3F EE D9 8A 73 EE 69 BF E0 0D 5C 57 EF F7 4F A7 18 4D 76 EB EB 3E AA 2B 79 C3 27 A6 C6 DB D3 1...
output:
1 2 6 5
result:
ok correct answer
Test #2:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
message 20 20 85 C4 91 58 77 23 A9 E5 44 8E 28 DC A2 51 13 AE 4E 3C 21 62 37 5A 41 45 8F CA C3 89 01 68 11 72 D8 75 72 ED EE 64 FA B0 05 45 6E F2 FD CE 9A AC 31 CA 88 83 34 D6 23 1F 8C 6D 9E 8C 42 40 7E 18 4C D1 D3 F2 02 20 51 20 14 0F 3D 27 0E 03 73 D7 C0 1F C3 1D D3 55 D9 AF 6E 76 77 28 24 1A 97 E...
output:
19 00 14 00 14 05 BD 1F 71 FA 3A 94 73 D2 D3 03 52 98 85 E0
input:
parts 19 00 14 00 14 05 BD 1F 71 FA 3A 94 73 D2 D3 03 52 98 85 E0 1 10 10 D0 0A D3 6D B9 31 31 76 54 15 CE 14 02 1A A2 8C 77 EB 8E 02 06 44 E4 F4 22 DB 66 F8 7E 38 C6 6A B7 5F E1 A0 0D F0 F5 8A AC DB B0 FB 26 E6 12 36 37 F1 6C AB B1 4C C0 11 B6 DE 71 C2 09 54 23 45 56 1E 4E C2 DA 1C 0E B5 D0 DC C8 1...
output:
6 6
result:
ok correct answer
Test #3:
score: 100
Accepted
time: 1ms
memory: 3528kb
input:
message 20 20 12 4F 58 0D 8B AB 72 D1 55 0F FC 74 28 E3 B0 02 9E FA 18 C0 82 72 32 EB 29 EF 9D 70 E6 2D AC 15 37 31 40 A4 36 B6 58 2C 4E C2 4D AC C5 0F D1 A8 B2 2D 43 ED 00 63 7C 3B 3E C5 94 49 92 7D 2C 69 2B 6A 15 95 7C FD 67 E4 AC EE 01 F8 78 5F 46 57 54 7D 03 92 36 85 D0 C0 B1 14 22 70 9D 06 4E C...
output:
19 00 14 00 14 5A 2B 21 30 1A B8 95 97 0F 9C DB C0 C0 E9 40
input:
parts 19 00 14 00 14 5A 2B 21 30 1A B8 95 97 0F 9C DB C0 C0 E9 40 9 10 10 12 4F 58 0D 8B AB 72 D1 55 0F 82 72 32 EB 29 EF 9D 70 E6 2D 4E C2 4D AC C5 0F D1 A8 B2 2D 92 7D 2C 69 2B 6A 15 95 7C FD 54 7D 03 92 36 85 D0 C0 B1 14 A7 42 36 1E F1 E2 B4 20 D7 FE 8D 5E 4F 0C 4E BF 46 32 0C 57 3C 09 56 B5 77 0...
output:
1 1 11 11 1 11 11 1 1 1 11 1 1 1 1 11 1 1
result:
ok correct answer
Test #4:
score: 100
Accepted
time: 1ms
memory: 3628kb
input:
message 43 37 EA A3 A3 FC CB 58 F5 40 43 D7 44 FA 09 74 25 84 25 7B 87 E4 98 7A 7F 9D 8D 73 46 AA F4 BF 73 DB EF 46 7D DA B5 7B C6 A2 A3 EF 7C 14 EE 10 1C DE 08 ED E8 2C BD F6 F7 2B 7D 82 B6 0D 0C 06 17 56 84 DD 96 29 77 C0 EE 70 EB 9F 16 A6 27 3A 32 52 AE 0E 31 A7 D2 1D B9 EC D2 20 3D 7D 84 12 4B 5...
output:
113 00 2B 00 25 C5 C2 F5 30 46 7F 52 65 51 41 4A 83 0F 06 AB F0 28 1D 26 23 F2 D7 AD 2E 63 87 1C 4F C1 17 8F 12 5B AA 7F B9 AA 96 84 A8 22 A1 60 0F 20 34 17 35 18 42 E5 CC 9E F9 85 2B 76 E7 99 8A 35 1B 51 10 45 A9 F9 47 86 94 46 2D 63 CD A2 0A 84 79 98 89 3A 47 D6 91 20 95 F1 4C 93 16 AE 58 C5 70 30...
input:
parts 113 00 2B 00 25 C5 C2 F5 30 46 7F 52 65 51 41 4A 83 0F 06 AB F0 28 1D 26 23 F2 D7 AD 2E 63 87 1C 4F C1 17 8F 12 5B AA 7F B9 AA 96 84 A8 22 A1 60 0F 20 34 17 35 18 42 E5 CC 9E F9 85 2B 76 E7 99 8A 35 1B 51 10 45 A9 F9 47 86 94 46 2D 63 CD A2 0A 84 79 98 89 3A 47 D6 91 20 95 F1 4C 93 16 AE 58 C5...
output:
10 9 25 16 17 16 9 16 26 9 24 17 7 19 3 16 17 2 15 23 13 26 24 20 13 3 21 8 16 17 7 8 6 21 3 6 6 15 27 6 9 12 16 18 12 11 32 14 6 12 1 16 19 24 31 12 5 2 18 25 7 9 1 6 10 17 16 8 3 16 3 7 13 21 18 1 14 10 8 7 21 1 26 5 4 13 22 16 6 15 29 12 15 12 31 10 5 16 4 15 26 3 3 11 17 27 9 3 12 16 6 10 12 8 1...
result:
ok correct answer
Test #5:
score: 0
Stage 2: Program answer Runtime Error
input:
message 47 36 BA 36 BC AF 3D 33 4E AA A4 CC 95 72 48 7F 1C 93 1B 8A CE A7 64 75 99 BF 62 8C A7 82 2E D3 52 D5 F6 E7 43 74 BD 8F BA CA 14 5D 79 4F 24 85 18 02 27 12 F2 CA 8F EF CF 8D 9A F4 09 F3 81 70 A7 0E 6F 9E CB 55 03 CC DA D6 18 0D A5 2F 61 D1 CB B9 99 DF B9 34 46 F3 0A E3 7E 09 E1 A1 26 AD E4 5...
output:
113 00 2F 00 24 99 73 F2 EC 5F 6C 9B C7 D2 A9 10 FF E1 FC 8F B4 D8 CB A5 DB 26 7E FE CC E0 94 D6 04 49 80 F9 CA 9A 73 B2 F7 66 B5 34 69 33 54 4C FE A1 D1 FF 9F 3C 6F 6B CC 09 E0 BE 92 9D 7B A3 62 01 64 8F 05 B5 14 94 26 55 7C 91 1E C5 81 2C E3 E6 AE 20 41 09 BC AF 7C B4 F9 76 24 90 08 0F B0 78 6F 57...
input:
parts 113 00 2F 00 24 99 73 F2 EC 5F 6C 9B C7 D2 A9 10 FF E1 FC 8F B4 D8 CB A5 DB 26 7E FE CC E0 94 D6 04 49 80 F9 CA 9A 73 B2 F7 66 B5 34 69 33 54 4C FE A1 D1 FF 9F 3C 6F 6B CC 09 E0 BE 92 9D 7B A3 62 01 64 8F 05 B5 14 94 26 55 7C 91 1E C5 81 2C E3 E6 AE 20 41 09 BC AF 7C B4 F9 76 24 90 08 0F B0 78...