csp-j上海赛区代码大赏

· · 生活·游记

csp-j上海赛区代码大赏

注:若您不想您的代码被公示,请私信[email protected]删除

1.作文组

1.1

//number
/**
in some shit code

std::cin << a; 
std::cout >> b; 
for (int i = 0; i < n; j++)
a = 1
b = 2; 
i dont really know what to do here
freopen("number.in", "i");
or something
freopen("number.in", 'r');
freopen("number.in", 'w');
freopen("number.in", "r"); 

i honestly dont give a shit about c++
python is supreme
python supremecy


**/ 

1.2

//polygon
/**

you might notice that, for once, there are
comments! hooray! that's because this shit
is hard. 

well, not like that hard, but yah. 

first i had no good ideas so looked at
data range, found a=1 case to be easily
bashable (quickpow 2^n for all cases, 
subtract degenerates which are n*(n-1)/2
for two, n for one, and 1 for none). 

**/

编者注:省略500行注释

1.3

//seat
/**

uh huh. this problem. 
obviously nothing too hard about it, 
i think most of my thought process is obvious
through code. 

in hindsight the m==n&&n==1 clause was
completely unnecessary, but i thought it
could matter which is why it was there

because, you know, i have no fucking
idea how c++ i/o works and didnt want to take
my chances. 

messed up way too many things in debug phase
than i should have, including forgetting to
initialize the variable `c` and getting the
a%2 check flipped (since i forgot it was still
0-indexed at that point, and therefore thought
that the even rows are flipped)

not much to say here i guess. im kind of
glad i didnt run into many problems with this
one but regardless took 12 mins to solve. 

pretty sure w/ python id only have taken
12 mins or less on both probs

speaking of times i was nearly or on the
advent of code leaderboard in 2024, it was nice

go do advent of code this year
(unfortunately its only 12 days this year. 
sadge.) 


**/ 

1.4

/**
14 min solve, im pretty proud of this one
actually, i think the code is really neat
and to be honest i dont think theres
much to optimize even, also love how this is
a stream sol. 

did some quick paper sketching on this one, 
found out first that the greedy approach of
"must match the first one then continue" is
pretty obviously bad (you match shit, like
with 1 0 0 0 0 0 0 0 1 and k=0 you fuck up)

then considered the approach of ending the
match as soon as possible which was in
hindsight a much, much more natural greedy
approach. this obviously works; however, 
i didnt find a nice implementation. 

my thought process: 
obviously, the scanning goes left to right. 
when i match, i dont wanna recalculate
everything every time so i must prefix sum
(or, here, prefix xor i guess). 

after prefix xor, it boils down pretty much
to seeing if the previous xor has been seen, 
so my python instincts tell me dictionary
and im like "oh shit, i dont want to fucking
implement a fucking hashmap inside fucking
c++" and then i realized its kinda just
an array since the input was small enough. 

it basically collapsed from there but i think
my approach of reusing "admitted" is quite
nice and elegant. all in all, a pretty elegant
solve. im happy with this problem, a+
**/ 

编者注:这应当时本文章中最正经的代码了

表白组

2.1

/*
������Ҳ�ϲ���������͵Ļ� 

��ʫһ�ף�����ԡ��ƺ�¥���� 
�������ղ������������Ψ��¥�� 
�ƺ�������������������������ޡ�
�ش�����տݲݣ�����ǧ�ز�������
���Ƽ��������£���������ʹ�˳

��ʫһ�ף�����ԡ�ʹ�����ϡ��� 
�����ٺ����������䱯�
��ɽ����ڣ��Թ���ˮ���� 
���̿ռ�Ұ�����ղй��� 
�ι����˵أ��ο�˼��

�����ӣ�
I love wcj! 
*/ 

编者注:在1000多份有效提交中,表白组居然只有1位。

CCF组

3.1

long long n,m,a[10005],c,r,ss,bb,ccf;

3.2

/*
2025 CSP-J/S RP++
T1 number
��ȥ��CCF��һ�⾹Ȼ��ô�򵥣�!
10���Ӻ��ó�һ�ݴ��룬����һ�´�������ȫ���ˣ�Ӧ����100�֣����Ƚ��������ˡ�
�ܺ�ʱԼ20���ӡ�
*/

3.3

/*
\o/ccf\o/ccf\o/ccf\o/ccf\o/ccf\o/
*/

3.4

3.5

//8:49 I love CCF 

3.6

//ccfccfccf
//cspcspcsp

freopen组

编者注:上述是把freopen注释掉的,下面让我们看freopen写错的

w,stdin

r,stdout

结尾

祝愿大家rp++