AtCoder Beginner Contest 209
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
#define mk make_pair
using namespace std;
const int mod=998244353;
const int M=1e8+5;
const int N=1e6+5;//?????????? 4e8
int x,y;
void solve()
{
cin>>x>>y;
cout<<max((int)0,y-x+1);
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
// printf("Case #%d: ",index);
solve();
// puts("");
}
return 0;
}
/*
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
#define mk make_pair
using namespace std;
const int mod=998244353;
const int M=1e8+5;
const int N=1e6+5;//?????????? 4e8
int n,m;
void solve()
{
cin>>n>>m;
int sum=0;
for(re i=1;i<=n;i++)
{
int x;
scanf("%lld",&x);
sum+=x;
}
sum-=n/2;
if(sum<=m) puts("Yes");
else puts("No");
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
// printf("Case #%d: ",index);
solve();
// puts("");
}
return 0;
}
/*
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
#define mk make_pair
using namespace std;
const int mod=1e9+7;
const int M=1e8+5;
const int N=1e6+5;//?????????? 4e8
int n;
int a[N],sum=1;
void solve()
{
cin>>n;
for(re i=1;i<=n;i++) scanf("%lld",&a[i]);
sort(a+1,a+n+1);
for(re i=1;i<=n;i++) sum=sum*(a[i]-(i-1))%mod;
cout<<sum;
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
// printf("Case #%d: ",index);
solve();
// puts("");
}
return 0;
}
/*
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
#define mk make_pair
using namespace std;
const int mod=1e9+7;
const int M=1e8+5;
const int N=1e6+5;//?????????? 4e8
struct node
{
int ver,edge,next;
}e[N];
int tot,head[N];
int f[N][64],t;
int n,q,d[N];
void add(int x,int y)
{
e[++tot].ver=y;
e[tot].next=head[x];
head[x]=tot;
}
void addedge(int x,int y)
{
add(x,y);add(y,x);
}
void bfs()
{
queue < int > q;
q.push(1);
d[1]=1;
while(q.size())
{
int x=q.front();q.pop();
for(re i=head[x];i;i=e[i].next)
{
int y=e[i].ver;
if(d[y]) continue;
d[y]=d[x]+1;
f[y][0]=x;
for(re j=1;j<=t;j++) f[y][j]=f[f[y][j-1]][j-1];
q.push(y);
}
}
}
int lca(int x,int y)
{
if(d[x]>d[y]) swap(x,y);
for(re i=t;i>=0;i--) if(d[f[y][i]]>=d[x]) y=f[y][i];
if(x==y) return x;
for(re i=t;i>=0;i--) if(f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i];
return f[x][0];
}
void solve()
{
cin>>n>>q;
t=(int)(log(n)/log(2))+1;
for(re i=1;i<n;i++)
{
int x,y;
scanf("%lld%lld",&x,&y);
addedge(x,y);
}
bfs();
while(q--)
{
int x,y;
scanf("%lld%lld",&x,&y);
int LCA=lca(x,y);
int z=d[x]+d[y]-2*d[LCA];
if(z&1) puts("Road");
else puts("Town");
}
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
// printf("Case #%d: ",index);
solve();
// puts("");
}
return 0;
}
/*
*/
坑点1、字母可以大写!!!!
在注意一下剪枝就行了
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include
#define inf 0x7fffffff
//#define ll long long
//#define int long long
//#define double long double
#define re int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
#define mk make_pair
using namespace std;
const int mod=1e9+7;
const int M=2e6+5;
const int N=2e6+5;//?????????? 4e8
char s[M];
struct node
{
int ver,next;
}e[M];
int tot,head[M];
void add(int x,int y)
{
e[++tot].ver=y;
e[tot].next=head[x];
head[x]=tot;
}
int n;
int d[N],a[N],in[N];
int id(char c)
{
if(c<='Z'&&c>='A') return c-'A'+26;
return c-'a';
}
int get(char a,char b,char c)
{
return id(a)*52*52+id(b)*52+id(c);
}
void dfs(int x)
{
d[x]=2;
for(re i=head[x];i;i=e[i].next)
{
int y=e[i].ver;
if(d[y]) continue;
d[y]=1;
for(re j=head[y];j;j=e[j].next)
{
int z=e[j].ver;
--in[z];
if(!in[z]) dfs(z);
}
}
}
void solve()
{
cin>>n;
for(re i=1;i<=n;i++)
{
scanf("%s",s);
int len=strlen(s);
int x=get(s[0],s[1],s[2]);
int y=get(s[len-3],s[len-2],s[len-1]);
in[x]++;
add(y,x);
a[i]=y;
}
for(re i=0;i<M;i++) if(!in[i]) dfs(i);
for(re i=1;i<=n;i++) if(d[a[i]]==1) puts("Aoki");
else if(d[a[i]]) puts("Takahashi");
else puts("Draw");
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
// printf("Case #%d: ",index);
solve();
// puts("");
}
return 0;
}
/*
*/