当前位置:网站首页>Arc135 partial solution
Arc135 partial solution
2022-07-03 22:41:00 【Hard working Lao Zhou】
Competition address
https://atcoder.jp/contests/arc135/tasks.
A - Floor, Ceil - Decomposition
https://atcoder.jp/contests/arc135/tasks/arc135_a.
Answer key
mathematical problem .
Give a positive integer X X X, f ( x ) f(x) f(x) Is the maximum product after one pass operation .
hypothesis X − = ⌊ x 2 ⌋ , X + = ⌈ x 2 ⌉ X_-=\lfloor \frac{x}{2} \rfloor,\ X_+=\lceil \frac{x}{2} \rceil X−=⌊2x⌋, X+=⌈2x⌉. We can write
f ( 1 ) = 1 f ( X ) = m a x ( X , f ( X − ) × f ( X + ) ) ∀ x ≥ 2 f(1)=1\\ f(X)=max(X, f(X_-) \times f(X_+))\ \forall x \ge 2 f(1)=1f(X)=max(X,f(X−)×f(X+)) ∀x≥2.
Now let's deduce the mathematical formula
f ( X − ) × f ( X + ) ≥ X − × X + ≥ X − 1 2 × X 2 ≥ X − 1 4 × X f(X_-) \times f(X_+) \ge X_- \times X_+ \ge \frac{X-1}{2} \times \frac{X}{2} \ge \frac{X-1}{4} \times X f(X−)×f(X+)≥X−×X+≥2X−1×2X≥4X−1×X.
such , We know when X ≥ 4 X \ge 4 X≥4 When , X − 1 4 × X ≥ X \frac{X-1}{4} \times X \ge X 4X−1×X≥X.
therefore :
f ( X ) = X ∀ X ≤ 4 f ( X ) = f ( X − ) × f ( X + ) ∀ X ≥ 5 f(X)=X\ \forall X \leq 4\\ f(X)=f(X_-) \times f(X_+)\ \forall X \ge 5 f(X)=X ∀X≤4f(X)=f(X−)×f(X+) ∀X≥5.
such , We can use DFS To achieve .
Let's take a look at the data range , 1 ≤ X ≤ 1 0 18 1 \leq X \leq 10^{18} 1≤X≤1018, The data is very big , Need to use memory search to optimize .
AC Code
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using PLL=pair<LL,LL>;
const LL MO=998244353;
unordered_map<LL, LL> M;
LL dfs(LL x) {
if (M.count(x)) {
return M[x];
}
M[x]=x;
if (x<=4) {
return M[x];
}
return M[x]=(dfs(x/2)*dfs((x+1)/2))%MO;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
LL x;
cin>>x;
cout<<dfs(x)<<"\n";
return 0;
}
B - Sum of Three Terms
https://atcoder.jp/contests/arc135/tasks/arc135_b.
Answer key
It's math again .
Hypothetical sequence A A A For the sequence that satisfies the condition , such
S i = A i + A i + 1 + A i + 2 ⇒ A i + 2 = S i − A i − A i + 1 S_i = A_i+A_{i+1}+A_{i+2} \Rightarrow A_{i+2}=S_i-A_i-A_{i+1} Si=Ai+Ai+1+Ai+2⇒Ai+2=Si−Ai−Ai+1.
When i = 1 i=1 i=1 When , A 3 = S 1 − A 1 − A 2 A_3=S_1-A_1-A_2 A3=S1−A1−A2, This equation has 3 3 3 An unknown number , So we assume that A 1 = a , A 2 = b A_1=a,\ A_2=b A1=a, A2=b, We can deduce the following
{ A 1 = a A 2 = b A 3 = S 1 − A 1 − A 2 = S 1 − a − b A 4 = S 2 − A 2 − A 3 = S 2 − S 1 + a A 5 = S 3 − A 3 − A 4 = S 3 − S 2 + b A 6 = S 4 − A 4 − A 5 = S 4 − S 3 − a − b A 7 = S 5 − A 4 − A 6 = S 5 − S 4 + a A 8 = S 6 − A 6 − A 7 = S 6 − S 5 + b . . . \begin{cases} A_1=a \\ A_2=b \\ A_3=S_1-A_1-A_2=S_1-a-b \\ A_4=S_2-A_2-A_3=S_2-S_1+a \\ A_5=S_3-A_3-A_4=S_3-S_2+b \\ A_6=S_4-A_4-A_5=S_4-S_3-a-b\\ A_7=S_5-A_4-A_6=S_5-S_4+a \\ A_8=S_6-A_6-A_7=S_6-S5+b\\ ... \end{cases} ⎩⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎧A1=aA2=bA3=S1−A1−A2=S1−a−bA4=S2−A2−A3=S2−S1+aA5=S3−A3−A4=S3−S2+bA6=S4−A4−A5=S4−S3−a−bA7=S5−A4−A6=S5−S4+aA8=S6−A6−A7=S6−S5+b...
such , We know the law . Next we need to know when there is a solution .
The existence of solutions , We can use the simplest sequence S 1 , S 2 , S 3 S_1, S_2, S_3 S1,S2,S3 Is there a pair ( a , b ) (a,b) (a,b) Satisfy , This will get .
{ S 1 ≤ a S 2 ≤ b a + b ≤ S 3 \begin{cases} S_1 \leq a\\ S_2 \leq b\\ a+b \leq S_3 \end{cases} ⎩⎪⎨⎪⎧S1≤aS2≤ba+b≤S3
therefore ,
When S 1 + S 2 > S 3 S_1+S_2>S_3 S1+S2>S3 When , There is no solution to the problem .
When S 1 + S 2 ≤ S 3 , ( a , b ) = ( S 1 , S 2 ) S_1+S_2 \leq S_3,\ (a,b)=(S_1,S_2) S1+S2≤S3, (a,b)=(S1,S2), Existence solution .
such , This problem becomes a simulation problem .
AC Code
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using PLL=pair<LL,LL>;
const int N=3e5+10;
LL s[N];
LL a[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
LL n;
cin>>n;
for (LL i=1; i<=n; i++) {
cin>>s[i];
}
LL sum=0;
LL c1=0;
for (LL i=1; i<n; i+=3) {
sum+=s[i]-s[i+1];
c1=max(c1, sum);
}
sum=0;
LL c2=0;
for (LL i=2; i<n; i+=3) {
sum+=s[i]-s[i+1];
c2=max(c2, sum);
}
sum=0;
LL c3=0;
for (LL i=3; i<n; i+=3) {
sum+=s[i]-s[i+1];
c3=max(c3, sum);
}
if (c1+c2+c3>s[1]) {
cout<<"No\n";
return 0;
}
a[1]=c1;a[2]=c2;a[3]=s[1]-c1-c2;
for (LL i=2; i<=n; i++) {
a[i+2]=s[i]-a[i]-a[i+1];
}
cout<<"Yes\n";
for (LL i=1; i<=n+2; i++) {
cout<<a[i]<<" ";
}
cout<<"\n";
return 0;
}
边栏推荐
- DR-NAS26-Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-5GHz-high-power-Mini-PCIe-Wi-Fi-Module
- [flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
- Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
- What are the common computer problems and solutions
- Team collaborative combat penetration tool CS artifact cobalt strike
- Codeforces Round #768 (Div. 1)(A-C)
- Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
- 2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
- [automation operation and maintenance novice village] flask-2 certification
- [template summary] - binary search tree BST - Basics
猜你喜欢
2 spark environment setup local
[automation operation and maintenance novice village] flask-2 certification
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
Shell script three swordsman awk
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
MLX90614 driver, function introduction and PEC verification
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
Yyds dry goods inventory Spring Festival "make" your own fireworks
随机推荐
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Ansible common usage scenarios
Why should enterprises do more application activities?
Shell script three swordsman awk
[sg function] lightoj Partitioning Game
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
Analysis report on the development prospect and investment strategy of global and Chinese modular automation systems Ⓟ 2022 ~ 2027
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
2022 electrician (elementary) examination questions and electrician (elementary) registration examination
Buuctf, web:[geek challenge 2019] buyflag
Hcip day 12 notes
How about agricultural futures?
Shiftvit uses the precision of swing transformer to outperform the speed of RESNET, and discusses that the success of Vit does not lie in attention!
Preliminary analysis of smart microwave radar module
油猴插件
. Net ADO splicing SQL statement with parameters
Kali2021.4a build PWN environment
Simple solution of m3u8 file format
finalize finalization finally final