How to AK ABC300
A - N-choice question
太简单,直接放代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline int read(){
int x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
int n,a,b,c[305];
signed main(){
n=read(),a=read(),b=read();
for(int i=1;i<=n;++i){
c[i]=read();
if(a+b==c[i]){
println(i);
return 0;
}
}
return 0;
}
B - Same Map in the RPG World
第一眼看上去好像没那么好做。但是会发现右移
时间复杂度
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline int read(){
int x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
int n,m;
char s[35][35],t[35][35],g[35],tmp[35][35];
inline void move(int x,int y){
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) tmp[i][j]=s[i][j];
for(int cnt=1;cnt<=x;++cnt){
for(int j=1;j<=m;++j) g[j]=tmp[1][j];
for(int i=1;i<n;++i) for(int j=1;j<=m;++j) tmp[i][j]=tmp[i+1][j];
for(int j=1;j<=m;++j) tmp[n][j]=g[j];
}
for(int cnt=1;cnt<=y;++cnt){
for(int i=1;i<=n;++i) g[i]=tmp[i][1];
for(int i=1;i<=n;++i) for(int j=1;j<m;++j) tmp[i][j]=tmp[i][j+1];
for(int i=1;i<=n;++i) tmp[i][m]=g[i];
}
}
inline bool same(char a[35][35],char b[35][35]){
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(a[i][j]!=b[i][j]) return 0;
}
}
return 1;
}
signed main(){
n=read(),m=read();
for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
for(int i=1;i<=n;++i) scanf("%s",t[i]+1);
for(int x=1;x<=n;++x){
for(int y=1;y<=m;++y){
move(x,y);
if(same(tmp,t)){
printf("Yes\n");
return 0;
}
}
}
printf("No\n");
return 0;
}
C - Cross
没难度。
首先注意到
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline int read(){
int x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
int n,m,cnt[105];
char s[105][105];
inline int calc(int x,int y){
int ans=0,limit=min(x-1,min(n-x,min(y-1,m-y)));
if(s[x][y]=='.') return 0;
for(int i=1;i<=limit;++i){
if(s[x+i][y+i]=='.'||s[x+i][y-i]=='.'||s[x-i][y+i]=='.'||s[x-i][y-i]=='.') break;
ans++;
}
return ans;
}
signed main(){
n=read(),m=read();
for(int i=1;i<=n;++i) scanf("%s",s[i]+1);
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cnt[calc(i,j)]++;
for(int i=1;i<=min(n,m);++i) printsp(cnt[i]);
return 0;
}
D - AABCC
为什么三重循环能过/fn
很明显,数的数量就是
由于
由于
然后可以加几个剪枝(
时间复杂度
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
#define re register
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
const int N=1e6+5;
const int SIZE=1<<14;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline char gc(){
static char buf[SIZE],*begin=buf,*end=buf;
return begin==end&&(end=(begin=buf)+fread(buf,1,SIZE,stdin),begin==end)?EOF:*begin++;
}
inline ll read(){
ll x=0;bool sgn=0;char ch=gc();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gc();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gc();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
ll n,ans,pf[N];
int cnt,prime[N];
bitset<N>not_prime;
inline void do_prime(int n){
not_prime[0]=not_prime[1]=1,cnt=0;
for(re int i=2;i<=n;++i){
if(!not_prime[i]){
prime[++cnt]=i;
pf[cnt]=1ll*i*i;
}
for(re int j=1;j<=cnt&&i*prime[j]<=n;++j){
not_prime[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
signed main(){
n=read();
do_prime(ceil(sqrt(n)));
for(re int i=1;i<=cnt&&prime[i]<=min(251ll,n);++i){
ll a=prime[i];
if(a*a*a*a*a>n)break;
for(re int j=i+1;j<=cnt&&prime[j]<=min((ll)1e4,n);++j){
ll b=prime[j];
if(b*b*b>n)break;
ll tmp=n/(a*a*b);
if(tmp<0)break;
int l=j+1,r=upper_bound(pf+1,pf+cnt+1,tmp)-pf-1;
if(l>r)continue;
ans+=(r-l+1);
}
}
println(ans);
return 0;
}
E - Dice Product 3
我们记
但是我们会发现
这样转移的时候用费马小定理算一下
由于
于是记搜即可。时间复杂度 map
。
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
const int mod=998244353;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline ll read(){
ll x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
ll n,i5;
inline ll ksm(ll a,ll b){
ll res=1;a%=mod;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod,b>>=1;
}
return res;
}
map<ll,ll>dp;
ll dfs(ll now){
if(now>=n) return now==n;
if(dp.count(now)) return dp[now];
ll ans=0;
for(int i=2;i<=6;++i) ans=(ans+dfs(now*i))%mod;
return dp[now]=ans*i5%mod;
}
signed main(){
n=read(),i5=ksm(5,mod-2);
println(dfs(1));
return 0;
}
F - More Holidays
首先计算出
否则,我们考虑用剩下的
我们用前缀和 upper_bound-1
即可。
最后对于所有的
不要忘记开 long long
!
时间复杂度
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
const int N=6e5+5;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline ll read(){
ll x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
ll ans,n,m,k,cntx,sum[N];
char s[N];
signed main(){
n=read(),m=read(),k=read();
scanf("%s",s+1);
for(int i=1;i<=n;++i){
cntx+=(s[i]=='x');
sum[i]=sum[i-1]+(s[i]=='x');
}
for(int i=n+1;i<=2*n;++i) sum[i]=sum[i-1]+(s[i-n]=='x');
ll cnt=k/cntx;
if(cnt>=m){
println(n*m);
return 0;
}
ans=1ll*n*cnt,k-=1ll*cnt*cntx;
ll len=0;
for(ll l=1;l<=n;++l){
ll r=0;
if(cnt==m-1) r=upper_bound(sum+l,sum+n+1,k+sum[l-1])-sum-1;
else r=upper_bound(sum+l,sum+2*n+1,k+sum[l-1])-sum-1;
len=max(len,r-l+1);
}
println(ans+len);
return 0;
}
G - P-smooth number
meet in the middle.
转换一下题目,实际上就相当于用
很明显这个数的数量也是质因子组合的数量,同样是因为唯一分解定理。
首先把
先搜第一半的,枚举当前质数的指数,只要不超过
然后第二部分的搜法一样,最后只需要求第一半有多少个数不超过
由于前一半的数比较小,所以如果是
时间复杂度
代码:
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define gt getchar
#define pt putchar
#define y1 y233
//typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128 lll;
//typedef __uint128_t ulll;
const int N=1e7+5;
using namespace std;
inline bool __(char ch){return ch>=48&&ch<=57;}
inline ll read(){
ll x=0;bool sgn=0;char ch=gt();
while(!__(ch)&&ch!=EOF){sgn|=(ch=='-');ch=gt();}
while(__(ch)){x=(x<<1)+(x<<3)+(ch-48);ch=gt();}
return sgn?-x:x;
}
template<class T>
inline void print(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);
}
template<class T>
inline void printsp(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(32);
}
template<class T>
inline void println(T x){
static char st[70];short top=0;
if(x<0)pt('-');
do{st[++top]=x>=0?(x%10+48):(-(x%10)+48),x/=10;}while(x);
while(top)pt(st[top--]);pt(10);
}
inline void put_str(string s){
int siz=s.size();
for(int i=0;i<siz;++i) pt(s[i]);
printf("\n");
}
ll n,a[N],ans;
int p,cnt,prime[105],tot;
bool not_prime[105];
inline void do_prime(int n){
not_prime[0]=not_prime[1]=1,cnt=0;
for(int i=2;i<=n;++i){
if(!not_prime[i]) prime[++cnt]=i;
for(int j=1;j<=cnt&&i*prime[j]<=n;++j){
not_prime[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
void dfs1(int now,int limit,ll val){
if(now>limit){
a[++tot]=val;
return;
}
dfs1(now+1,limit,val);
while(1){
val*=prime[now];
if(val>n) break;
dfs1(now+1,limit,val);
}
}
void dfs2(int now,int limit,ll val){
if(now>limit){
ll tmp=n/val;
ll sum=upper_bound(a+1,a+tot+1,tmp)-a-1;
ans+=sum;
return;
}
dfs2(now+1,limit,val);
while(1){
val*=prime[now];
if(val>n) break;
dfs2(now+1,limit,val);
}
}
signed main(){
n=read(),p=read();
do_prime(p);
dfs1(1,cnt/3,1);
sort(a+1,a+tot+1);
dfs2(cnt/3+1,cnt,1);
println(ans);
return 0;
}
Ex - Fibonacci: Revisited
是多项式,这下 AK 不了了……
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!