Codeforces Round #627(Div. 3) 문제 해결
63395 단어 codeforces 경기codeforces
이 경기를 수속장(인당 A K AK AK장)이라고도 부른다
A Y e t A n o t h e r T e t r i s P r o b l e m\mathrm{A\Yet\Another\Tetris\Problem} A Yet Another Tetris Problem
#include
using namespace std;
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
bool rem;
int t,n,s,i,a;
int main()
{
t=read();
while(t--)
{
n=read(),s=read();
s&=1;
rem=0;
for ( int i=2;i<=n;i++ )
{
scanf("%d",&a);
if(s!=(a&1))rem=1;
}
puts((rem&&n>1?"NO":"YES"));
}
return 0;
}
B Y e t A n o t h e r P a l i n d r o m e P r o b l e m\mathrm{B\Yet\Another\Palindrome\Problem} B Yet Another Palindrome Problem
#include
using namespace std;
const int N=10000;
int T,n,pos[N],a[N];
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
int main()
{
T=read();
while (T--)
{
n=read();
memset(pos,0,sizeof(pos));
bool ww=false;
for ( int i=1; i<=n; ++i)
{
a[i]=read();
if (!pos[a[i]]) pos[a[i]]=i;
else if (i-pos[a[i]]>1) ww=true;
}
if(n<3) ww=false;
if(ww) printf("YES
");
else printf("NO
");
}
return 0;
}
C F r o g J u m p s\mathrm{C\Frog\Jumps} C Frog Jumps
#include
using namespace std;
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
string str;
int t,n,last,d,i;
inline void solve()
{
cin>>str;
int n=str.size();
int last=0,d=0;
for ( int i=0;i<n;i++ )
if(str[i]=='R')d=max(d,i+1-last),last=i+1;
printf("%d
",max(d,n+1-last));
}
int main()
{
t=read();
while(t--) solve();
return 0;
}
D P a i r o f T o p i c s\mathrm{D\Pair\of\Topics} D Pair of Topics
#include
#define int long long
#define lowbit(x) x&(-x)
using namespace std;
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
const int N=4e5+5;
int n,m,ans,a[N],b[N],c[N],d[N],e[N];
inline void add(int x,int val)
{
while(x<=m)
{
c[x]+=val;
x+=lowbit(x);
}
}
inline int ask(int x)
{
int ret=0;
while(x)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
}
signed main()
{
n=read();
for ( int i=1;i<=n;i++ ) a[i]=read();
for ( int i=1;i<=n;i++ )
{
b[i]=read();
d[i*2-1]=a[i]-b[i];
d[i*2]=b[i]-a[i];
}
sort(d+1,d+2*n+1);
m=unique(d+1,d+2*n+1)-d-1;
for ( int i=1;i<=n;i++ )
{
int p=lower_bound(d+1,d+m+1,b[i]-a[i])-d;
ans+=i-ask(p)-1;
p=lower_bound(d+1,d+m+1,a[i]-b[i])-d;
add(p,1);
}
printf("%lld
",ans);
return 0;
}
E S l e e p i n g S c h e d u l e\mathrm{E\Sleeping\Schedule} E Sleeping Schedule
#include
using namespace std;
int g[2005],f[2005];
bool vis[2005],bo[2005];
#define mem(i,j) memset(i,j,sizeof i)
#define mec(i,j) memcpy(i,j,sizeof i)
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
int n,h,l,r,i,a,j,ans=0;
int main()
{
n=read();
h=read();
l=read();
r=read();
bo[0]=1;
while(n--)
{
a=read();
for ( int i=0;i<h;i++ )
if(bo[i])
{
j=(i+a)%h;
g[j]=f[i]+(j>=l&&j<=r);
vis[j]=1;
}
for ( int i=0;i<h;i++ )
if(bo[i])
{
j=(i+a-1)%h;
g[j]=max(g[j],f[i]+(j>=l&&j<=r));
vis[j]=1;
}
mec(f,g);
mem(g,0);
mec(bo,vis);
mem(vis,0);
}
for ( int i=0;i<h;i++ )
if(bo[i])
ans=max(ans,f[i]);
printf("%d
",ans);
return 0;
}
F M a x i m u m W h i t e S u b t r e e\mathrm{F\Maximum\White\Subtree} F Maximum White Subtree
#include
using namespace std;
inline int read()
{
int sum=0,ff=1; char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-') ff=-1;
ch=getchar();
}
while(isdigit(ch))
sum=sum*10+(ch^48),ch=getchar();
return sum*ff;
}
const int N=2e5+5;
int n,m,col[N],c[N],f[N];
vector<int> ma[N];
inline void dfs(int u,int fa)
{
if(col[u]) f[u]=1; else f[u]=-1;
for ( int i=0;i<ma[u].size();i++ )
{
int v=ma[u][i];
if(v==fa) continue;
dfs(v,u);
f[u]=max(f[u],f[v]+f[u]);
}
}
inline void dfs2(int u,int fa)
{
if(u!=1)
{
if(f[u]<0) f[u]=max(f[u],f[u]+f[fa]);
else f[u]=max(f[u],f[fa]);
}
for ( int i=0;i<ma[u].size();i++ )
{
int v=ma[u][i];
if(v==fa) continue;
dfs2(v,u);
}
}
int main()
{
n=read();
for ( int i=1;i<=n;i++ ) col[i]=read();
for ( int i=1;i<n;i++ )
{
int x,y;
x=read(),y=read();
ma[x].push_back(y);
ma[y].push_back(x);
}
dfs(1,0);
dfs2(1,0);
for ( int i=1;i<=n;i++ ) printf("%d ",f[i]);
return 0;
}
E E\mathrm{EE} EE 절차
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Global Round 7 문제 해결(A-D2)C o d e f o r c e s G l o b a l R o u n d 7 (A - D 2)\mathrm {Codeforces\Global\Round\7 (A-D2)} Codeforces Global Round ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.