[AtCoder] AtCoder Grand Contest 040 problem-solving report

Click here to enter the competition

\ (A \) :> <( Click here to see surface title )

Generally meaning of problems: to give you a length \ (. 1-n-\) , the \ (<\) and \ (> \) strings of the first \ (I \) character bit represents \ (I \ ) number and \ (i + 1 \) number of magnitude relation, the elements required by the array of non-negative integers and minimum.

I want to send sub-themes for a few minutes before doing it, really retire early warning ......

Obviously, the number is less than for all sides, and we give it a value for the \ (0 \) , and then extended to them from side to side.

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 500000
#define Gmax(x,y) (x<(y)&&(x=(y)))
using namespace std;
int n,H=1,T=0,a[N+5],q[N+5],vis[N+5];string s;
int main()
{
    RI i,k;cin>>s,n=s.length()+1,s="%"+s+"%",s[1]=='<'&&(q[++T]=1),s[n-1]=='>'&&(q[++T]=n);
    for(i=2;i^n;++i) s[i-1]=='>'&&s[i]=='<'&&(q[++T]=i);W(H<=T) k=q[H++],
        s[k-1]=='>'&&(Gmax(a[k-1],a[k]+1),!vis[k-1]&&(vis[q[++T]=k-1]=1)),//向左扩展
        s[k]=='<'&&(Gmax(a[k+1],a[k]+1),!vis[k+1]&&(vis[q[++T]=k+1]=1));//向右扩展
    long long ans=0;for(i=1;i<=n;++i) ans+=a[i];return printf("%lld",ans),0;//统计答案
}

\ (B \) : Two Contests ( Click here to see the problem surface )

Roughly meaning of the questions: There \ (n \) intervals, so you put it into a non-empty two parts, so that the two parts of the interval and the size of the largest intersection.

First, we need to know, for some interval \ ([L_i, r_i] \) , their intersection size \ (max (min \ {r_i \} - max \ {L_i \} + 1,0) \) .

Accordingly, first sorting section the left end, and then enumerate a range wherein a maximum value of the left point \ (L_i \) , then the other point of the left maximum interval \ (L_n \) .

For the right point, there are two possibilities.

Provided the first \ (1 \ sim i \) line segments smallest \ (R & lt \) of \ (R_ {min} \) , the maximum of \ (R_ {max} \) , the first \ (i + 1 \ sim n-\) smallest \ (R & lt \) of \ (Mn \) .

Then the optimal case, two sets of \ (min \ {r_i \} \) or are \ (min R_ {}, Mn \) , or are \ (r_ {max}, min (r_ {min} , Mn) \) .

Determine the points left and right point, we can therefore update the answer.

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Gmax(x,y) (x<(y)&&(x=(y)))
using namespace std;
int n;set<int> p,q;
struct Il {int x,y;I bool operator < (Con Il& o) Con {return x<o.x;}}s[N+5];
class FastIO
{
    private:
        #define FS 100000
        #define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
        #define tn (x<<3)+(x<<1)
        #define D isdigit(c=tc())
        char c,*A,*B,FI[FS];
    public:
        I FastIO() {A=B=FI;}
        Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
}F;
int main()
{
    RI i,j,t,ans=0;for(F.read(n),i=1;i<=n;++i) F.read(s[i].x),F.read(s[i].y);
    for(sort(s+1,s+n+1),i=1;i<=n;++i) q.insert(s[i].y);//排序,一开始默认所有线段在第二个集合
    for(i=1;i<=n;++i) q.erase(s[i].y),p.insert(s[i].y),t=0,//枚举一个区间的左端点最大值,把对应右端点移入第一个集合中
        Gmax(t,max(*--p.end()-s[i].x+1,0)+max(min(*p.begin(),*q.begin())-s[n].x+1,0)),//第一种情况
        Gmax(t,max(*p.begin()-s[i].x+1,0)+max(*q.begin()-s[n].x+1,0)),Gmax(ans,t);//第二种情况,更新ans
    return printf("%d",ans),0;
}

\ (C \) : Neither AB NOR BA ( Click here to see the problem surface )

Generally meaning of problems: For one of \ (A, B, C \ ) string of three kinds of characters, each two consecutive not be deleted ABor BAcharacters, the number of required length \ (n-\) character you can delete the empty string.

First, we consider there is no \ (C \) situations.

In this case, if we put on the odd bit \ (A \) becomes \ (B \) , \ (B \) to \ (A \) , can be found, if and only if \ (A \) and \ (B \) number of the same, can delete this empty string.

At the same time due to the string with the original string correspondence after the change, so long as the number of strings obtained after the change, you can find the answer.

Consider the presence \ (C \) , since \ (C \) can be regarded as \ (A \) or \ (B \) any of one, so long as \ (A \) and \ (B \) of the difference between the number of number of less than or equal \ (C \) number, may delete empty.

The answer may consider inclusion and exclusion, i.e. obtains \ (A \) and \ (B \) the difference is greater than the number \ (C \) giving the number of the programs, and then subtracting the total number scheme.

At this time there must be \ (A \) or \ (B \) certain kind of there \ (I \) th ( \ (I> \ FRAC N2 \) ), the remaining \ (Ni \) positions may fill in any other letters and \ (C \) .

I.e., the number of the program in this case is:

\[C_n^i\times 2^{n-i}\]

Therefore, pre-factorial and factorial inverse, \ (O (the n-) \) enumeration \ (i \) , statistics can answer.

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 10000000
#define X 998244353
#define C(x,y) (1LL*Fac[x]*IFac[y]%X*IFac[(x)-(y)]%X)
using namespace std;
int n,Fac[N+5],IFac[N+5];
I int Qpow(RI x,RI y) {RI t=1;W(y) y&1&&(t=1LL*t*x%X),x=1LL*x*x%X,y>>=1;return t;}//快速幂
int main()
{
    RI i,t=0;for(scanf("%d",&n),Fac[0]=i=1;i<=n;++i) Fac[i]=1LL*Fac[i-1]*i%X;//预处理阶乘
    for(IFac[n]=Qpow(Fac[n],X-2),i=n-1;~i;--i) IFac[i]=1LL*IFac[i+1]*(i+1)%X;//预处理阶乘逆元
    for(i=n/2+1;i<=n;++i) t=(1LL*C(n,i)*Qpow(2,n-i)+t)%X;//计算答案
    return printf("%d",(Qpow(3,n)-2*t%X+X)%X),0;//容斥,注意乘2
}

\ (D \) : Balance Beam (accounting for pit to be filled)

\ (E \) : the Prefix Suffix Addition (accounting for pit to be filled)

\ (F \) : Two Pieces (accounting for pit to be filled)

Guess you like

Origin www.cnblogs.com/chenxiaoran666/p/AtCoderAGC040.html