QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884059#9909. 阿尔塔尔 2ningago100 ✓96ms3712kbC++143.9kb2025-02-05 21:09:122025-02-05 21:09:13

Judging History

This is the latest submission verdict.

  • [2025-02-05 21:09:13]
  • Judged
  • Verdict: 100
  • Time: 96ms
  • Memory: 3712kb
  • [2025-02-05 21:09:12]
  • Submitted

answer

#include"altar.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
#include <random>

namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
// #define ll long long
// #define inf 0x3f3f3f3f
#define int long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
	return getchar();
#else
	if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
	return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}

void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;

void putc(char c)
{
#ifdef LOCAL
	putchar(c);
#else
	*oS++ = c;
	if(oS == oT) Flush();
#endif
#define putchar ERR
}

template <typename T = int> T read()
{
	T x = 0, f = 1; char c = getc();
	for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
	top = 0;
	if(x < 0) putc('-'), x = -x;
	if(!x) sta[top = 1] = 0;
	for(; x; x /= 10) sta[++top] = x % 10;
	for(; top; ) putc(sta[top--] ^ 48);
	if(c) putc(c);
}

int readstr(char *s, int base)
{
	int idx = base - 1; char c = getc();
	for(; !(isdigit(c) || isalpha(c) || c == '(' || c == '?'); c = getc());
	for(;   isdigit(c) || isalpha(c) || c == '(' || c == '?' ; c = getc()) s[++idx] = c;
	return idx - base + 1;
}

void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
	for(; *s; s++)
	{
		if(*s != '%') { putc(*s); continue; }
		s++; if(*s == 'd') print(x, 0);
		else if(*s == 'c') putc(x);
		printf(s + 1, rest ...);
		return;
	}
}

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }

// 核心:答案的权值 <= 2,即在一个竞赛图上一定存在一个点到其他所有点距离 <= 2

// 由出度证明:考虑出度最大的点,若它的权值 >= 3,那么第三层的点一定出度严格比它大(1+第二层),与最大矛盾。故出度最大点的权值一定 <= 2
// 归纳法证明:若存在入度 = 0 的点那么它权值 = 1,一定合法。否则对于任意一个 x,已知它的入点构成的导出子图归纳合法,导出子图中合法的那个点到 x 和 x 的出点距离都 <= 2,故它仍然合法。

// 由归纳法,每次随机一个点递归到入点即可,每次期望 / 2。

std::mt19937 rnd(114514);
int n;

int solve(int _n)
{
	// memset(h, idx = -1, sizeof(h));
	n = _n;
	std::vector <int> now, tmp;
	for(int i = 1; i <= n; i++) now.push_back(i);
	while((int)now.size() > 1)
	{
		std::vector <int>().swap(tmp);
		std::shuffle(now.begin(), now.end(), rnd);
		int x = now[0], sz = now.size();
		for(int i = 1; i < sz; i++) if(sense(now[i], x)) tmp.push_back(now[i]);
		if(tmp.empty()) return x;
		std::swap(tmp, now);
	}
	return now[0];
}

#ifdef int
	#undef int
#endif
}

int altar(int n){
	return uvu::solve(n);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 95ms
memory: 3584kb

input:

300
$NE[`FN8(GUPU5JN"+-?S9BD8AV29KPSV*_J33@A;BIC>PLD;?
.O`)V,Q^WPM3M4>+@W$GJ`Y_.Z`%'?1?VO645/Y";"E_RDLBU#
,V\*=ZO>6J0[,*9XVA[<<O\RJN9]B`&^4-`QV(&Z=$T7(05"2!
(EOLI9X](E0V.HG`B&5QBMXJ-<8;ITS5_FL>S-BEC[FUH9?J'"
AH#FYE-:C9OC>N*WMNIHYIDSSG=2Z2:0/B/B=-]QBJ^61]LG_!
CL92HRY]<1P<VF$>Q>;<F*1>)DH'5$VA3>A&1'0;Y...

output:

Accepted.
175376
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 584.586667

Subtask #2:

score: 10
Accepted

Test #2:

score: 10
Accepted
time: 74ms
memory: 3456kb

input:

300
`XP``88`X:`X>Y`]@X^P`](^P[WY^`^V^P`NX`[L`@P```\^^@
6TTR>ADPJM9+/E@WNROG<_$_86,9W_OY?X`C\0Z&`HX^\X>]U/
):ZQ'QR&1'-&(S/\W18D.`"`LK&):>6=P\?R^HEC>TZ]VD//;(
X]]@0Y[\/\_K$\H><O`ZG`I`6V'GPP,O`^P^_4@^`\^``>00P$
37/M$=="F&4RBMTO.UV=T@Q`K;"378&X\O8=`*LY`]O@`KDDW"
.0(X$/_GSCLY1_:X'\;OZ0Y@6NB:\\C\>`<O`E8]@...

output:

Accepted.
171214
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 570.713333

Test #3:

score: 10
Accepted
time: 95ms
memory: 3584kb

input:

300
5OE?M21ZC3S/R%Q3L;V2'%M1ZRB"0^#J%_.A5(KTQ-=UM-1-`&
_73M@`3L&)W\.!1Y-T!+?B_&1'=BZBPDGGHWT*!=I]^*/T)Y90
%HX#N%@(=R.Q,)2R$RCRSAHG1+FBU7?&&?PI)/^;\1/]3$/]T'
%!\M8T)7:0U_*E^GG.@C,!0=\MR4<61>D$<<5W<P,%_N,!Z<1"
\?+TT5<N#+&YOV77_-5*"C8B(]9=Q)1V!4?GV!R%,36/7Q:&$!
1D]6'2EO3S)%B`1.4GJ48,&Q09S:[T\\"L\(KS'>^...

output:

Accepted.
175404
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 584.680000

Subtask #3:

score: 80
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #4:

score: 80
Accepted
time: 77ms
memory: 3584kb

input:

300
.&(6P[JSS(#6@H4\H?I8>56PGMHQ9OLB`X%0&SZ`[0\Z9GSXT/
GCDK8^5:Z$BKPRJ^40UL/CK(4W49%WVQ`:CH#Z]@^H^=-4Z\:(
@R@```_]`\@`X\_`\0`X8@XP```OO`_Z`>Z<L__`_``@_Z^^N(
III[6,67_1I[<-;`5$^KDI[RE^%'B>.]@GIJ1/`(N:0(S5_=W"
555^KF+,@)5^.'N@[B?V25^9S?#DQO'_04U5)H`LXMH$:+@0\!
+/K@^TFF0'K_/HW0^1P[IK?.:0BR=8$`P*?+ET`X@...

output:

Accepted.
172186
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 573.953333

Test #5:

score: 80
Accepted
time: 75ms
memory: 3584kb

input:

300
XVN`0_.XL``\XVVPLPF``^0OP_WX`@@;`9U`VN8(6(<`[@`5P8
\[50(W'\VW`=\Q9VRHSV[?(X(@TL=P0M;)SK[GCBK$M@]P8CG$
6>IF$$BR;\@'99ECY!2+2H$[DN*6EX(1.%*6-421V!W/94,1D"
)!%CBB!1B""#))!11!)E!1"B17!!#A$)!#E)A!)A9!#!-A!I!!
8```_``````@@8`P`X````__\<@``^\`D^`8`_^X@_`P`^T`@"
K$N=9)-7<`T!$D5%()3*[[email protected]]_!CB)JC:+#K'...

output:

Accepted.
173945
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 579.816667

Test #6:

score: 80
Accepted
time: 95ms
memory: 3584kb

input:

300
6'>'&@"W)D]U@'WOF^[Y#\))QW@QF^:+VKURFY-U$1\")W0GY4
LR1DCFA;E2?;'"<`Q_=]B>%-9T0:[[OM;>\[+5-;,KN>5\&8]*
F:I228!E1)0^PBL<98PMQ/#GM^H9*>'7NK>>&+#P!U7CK^C*_%
[email protected](JO<:A:.=:Q!NWH`\EZ:0%V9E5J-<\Z9>3:`JIK8@[C$
W`(,<V`_L5M.TV&RB?IE"5K.A"_NN9@(!^Q!82NU43[@#5AF?!
Q!S>$VRKZ(/*3(<&(ALZLP/Z<Y$9M6:^/45>?8(2W...

output:

Accepted.
176920
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 589.733333

Test #7:

score: 80
Accepted
time: 96ms
memory: 3584kb

input:

300
'@[email protected]^M8%D'@ETE<\7'!6L8ELW89WC2FDO6',\*B0V\*>D=
$PF'4\GT5XLD4D0S:YBVD$ILH$S*>*M\RLQ2W;J.MEQO_V-G2+
RVSD*>49P\F2A2(Z-^U_RBSVS"Z%P.WMU=YI,01?739$N?%T)(
8O#-.8'<-+%0$(^O:9MBFP-@D^P)%\&F"2\L5+FAQX(5AVU]\!
EK,P:9Y;>D-YX)N2XR$F&LZ3DPA\U;5%\`A-F;<0<B)H%J.RI!
46FU/-]NO2WNLE2A^YACTV=)B8Q>+,<[N<!E7^NHJ...

output:

Accepted.
174252
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 580.840000

Test #8:

score: 80
Accepted
time: 96ms
memory: 3712kb

input:

300
5RL\JZHZE-Q]$GA?H?I(6J\%3VAO^,1/:GZ,@RTUWU#1WXRIA%
K&V^W]T5;/?;",3O40VBO/>HJ;13_E;HMS[A(Y>K;[")`\9U1#
C@&F&"GU_]D3`-F1-U%JC>\@[TT?E6<M[-LO^,4]"Q*[#3_^T'
PQ`14LE2J=]WN:L8LF%X/R#S6^O3"7:`E4K'ULU"`H`,GX:27"
[(!22A*N0RI%PX.'$>RJ;H_XUAJ(:8#Q-TK<VC-@)=NO!54X."
,M.VH,;53(O:<W[Z3:SH"MA96PC5SV_0REI2^O5QW...

output:

Accepted.
174193
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 580.643333

Test #9:

score: 80
Accepted
time: 91ms
memory: 3584kb

input:

300
"!"!A"FAO!,#:!!CZA-Q!!!%KQ)%Q=1I"#E1%"#+6!!!\+",1!
#!)"QAQ#1Q"*-#21%%"9!!3#L!)!2IBE!"293,*)L!%C9%A2+%
4]`Z:`RZ@KH8OB_=PP`>_^,,`^_`W\69^`@`[`P`R`G^X4S\&(
!11!%95!%)2+C17!(2!/!!AQP1D1F$#&3"!]]!3,+!$#(!2"#!
A>`GP^>_H[JF\:@`H`*P'U4WX`@YR?6PJ`X0?L`@/`:PZOM_F!
/_&$<`_@Z6`[.V`\`^N@(:<[L`_];HOD=0D(P_V@H...

output:

Accepted.
176631
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 588.770000

Test #10:

score: 80
Accepted
time: 31ms
memory: 3584kb

input:

121
T@5:-E]M+A*@^IJ>O.4M
J.K-'G@7&Y%L/=U%4G.@
I'V',2<L#=C6C/;H*T%,
O-V)>@,+G3)R7/K/*%6#
8A;OLO&5@:F30(5H-Q+"
WI_9*[<8"4O3R32=<G]"
?5@%E]M+E*7N+IJG-4_
0K/37XW6SEP/NU?4G*@
[<]U&I0TKNJ1DHSN->#
D+DEEG6B/R,8"FVN:T&
`D/>2YRM9,OUYJ5L<8!
8"HO)N=7^*6+]&OF0$!
#'LI<$R?EJUT2V:$I4
!$^]NB[,\5\\I\E1W*
C2_[W1N&=+N=...

output:

Accepted.
89748
u2930hioewfbjkadvhhi4t

result:

ok Perfect. 299.160000