QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385202 | #5809. Min Perimeter | cmk666 | 5 | 52ms | 78368kb | C++23 | 9.0kb | 2024-04-10 16:23:48 | 2024-04-10 16:23:50 |
Judging History
answer
/* _ _ _ _ __ __ __
/ \ _ _ | |_ | |__ ___ _ __ _ ___ _ __ ___ | | __ / /_ / /_ / /_
/ _ \ | | | | | __| | '_ \ / _ \ | '__| (_) / __| | '_ ` _ \ | |/ / | '_ \ | '_ \ | '_ \
/ ___ \ | |_| | | |_ | | | | | (_) | | | _ | (__ | | | | | | | < | (_) | | (_) | | (_) |
/_/ \_\ \__,_| \__| |_| |_| \___/ |_| (_) \___| |_| |_| |_| |_|\_\ \___/ \___/ \___/
[Created Time: 2024-04-10 15:36:35]
[Last Modified Time: 2024-04-10 16:23:42] */
#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 DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
inline constexpr int _READ_SIZE = 1 << 18;
inline 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);
if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
}
return *_read_ptr++;
}
#else
#include<sys/mman.h>
inline static const char *_read_ptr = (const char *)mmap(nullptr, 0x7fffffff, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
inline constexpr int _WRITE_SIZE = 1 << 18;
inline 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 struct _auto_flush
{
inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
} _auto_flush;
#endif
template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
template <> inline constexpr bool _is_signed < __int128 > = true;
template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
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();
}
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 >
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); }
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 >
inline void write(T x)
{
char buffer[numeric_limits < T >::digits10]; 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) { write(x), pc(32), print(y...); }
template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_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 FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
using P = pair < int, int >; using ld = double;
#define fi first
#define se second
struct H
{
constexpr static int N = 1 << 24;
struct E { P u; vector < int > v; int nxt; } e[1000009];
int h[N], cnt;
inline int hsh(const P &x)const { return ( (ll)1e9 * x.fi + x.se ) & ( N - 1 ); }
inline void clear() { while ( cnt ) h[hsh(e[cnt--].u)] = 0; }
inline int find(const P &u)
{
for ( int i = h[hsh(u)] ; i ; i = e[i].nxt ) if ( e[i].u == u ) return i;
return 0;
}
inline auto &operator[](const P &u)
{
int &hu = h[hsh(u)];
for ( int i = hu ; i ; i = e[i].nxt ) if ( e[i].u == u ) return e[i].v;
return e[++cnt].u = u, e[cnt].v.clear(), e[cnt].nxt = hu, hu = cnt, e[cnt].v;
}
} mp; int n, x, y, o; P a[1000009]; ld mn, ans; vector < int > nw;
inline ld dis(int x, int y) { return hypot(a[x].fi - a[y].fi, a[x].se - a[y].se); }
inline void build(int n)
{
mp.clear();
For(i, 1, n) mp[P(a[i].fi / ( ans / 2 ), a[i].se / ( ans / 2 ))].push_back(i);
}
inline void work()
{
static int _; cout << "Case #" << ++_ << ": ";
read(n);
For(i, 1, n) read(a[i]);
shuffle(a + 1, a + n + 1, rnd), ans = dis(1, 2) + dis(1, 3) + dis(2, 3), build(3);
For(i, 4, n)
{
x = a[i].fi / ( ans / 2 ), y = a[i].se / ( ans / 2 ), nw.clear(), mn = 1e10l;
if ( o = mp.find(P(x - 1, y - 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x - 1, y )) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x - 1, y + 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x , y - 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x , y )) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x , y + 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x + 1, y - 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x + 1, y )) ) for ( int j : mp.e[o].v ) nw.push_back(j);
if ( o = mp.find(P(x + 1, y + 1)) ) for ( int j : mp.e[o].v ) nw.push_back(j);
For(j, 0, (int)nw.size() - 1) For(k, j + 1, (int)nw.size() - 1)
mn = min(mn, dis(i, nw[j]) + dis(i, nw[k]) + dis(nw[j], nw[k]));
if ( mn < ans ) ans = mn, build(i); else mp[P(x, y)].push_back(i);
}
cout << fixed << setprecision(9) << ans << '\n';
}
int main() { int t; nw.reserve(1 << 10), read(t); For(tt, 1, t) work(); return 0; }
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 52ms
memory: 78368kb
input:
15 3 2 6 7 0 3 0 3 713 269 371 79 455 421 3 91983245 637281504 756917015 312173515 869576338 436726680 10000 14761642 78236002 9047458 47951098 5238002 27761162 476182 2523742 1428546 7571226 26190010 138805810 21904372 116092132 18094916 95902196 43332562 229660522 55237112 292754072 52380020 27761...
output:
Case #1: 17.893012206 Case #2: 1042.844834964 Case #3: 1711142102.791327000 Case #4: 90912.296374033 Case #5: 3.414213562 Case #6: 26.153830342 Case #7: 1701.012681096 Case #8: 2865438.191993871 Case #9: 2020088.337226320 Case #10: 1792106.037292071 Case #11: 2019352.542909729 Case #12: 2530195.7280...
result:
ok correct! (15 test cases)
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
15 3 501691275 344354353 167768963 536043860 249445040 557426549 4 1000000000 0 0 0 1000000000 1000000000 0 1000000000 1000000 138925776 669369648 61257680 295150640 170762328 822763944 55483472 267329456 97736936 470914328 84041848 404928904 18463588 88960924 124429360 599523280 95066048 458045504 ...