Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
33087 | masppy | 【S】T3 | C++ | 解答错误 | 70 | 19 MS | 27808 KB | 2957 | 2024-10-04 14:02:14 |
#include<bits/stdc++.h> #define ll long long #define lson pos<<1 #define rson pos<<1|1 using namespace std; const int maxn=8e5+10; const ll mod=1e9+7; const ll inf=1e9+10; ll n,m,ans=0,k; ll a[maxn],siz[maxn],vis[maxn]; char c[maxn]; vector<int> q[maxn]; struct node{ int pos,t; }p[maxn]; ll q_pow(ll a,ll b){ ll tmp=1; while(b){ if(b&1){ tmp=(tmp*a)%mod; } b>>=1; a=(a*a)%mod; } return tmp; } bool cmp(node a,node b){ return a.t>b.t; } int main(){ // freopen("loop.in","r",stdin); //freopen("loop.out","w",stdout); scanf("%s",c+1); n=strlen(c+1); scanf("%lld",&k); if(k==1){ memset(vis,-1,sizeof(vis)); int x=200000,y=200000; q[x].push_back(y); for(int i=1;i<=n;i++){ if(c[i]=='D') y--; else if(c[i]=='U') y++; else if(c[i]=='L') x--; else x++; q[x].push_back(y); } for(int i=0;i<=400000;i++){ if(q[i].empty()) continue; int siz=q[i].size(); for(int j=0;j<siz;j++){ int v=q[i][j]; // cout<<v<<endl; if(vis[v]!=i) ans++; vis[v]=i; } } printf("%lld",ans); fclose(stdin); fclose(stdout); return 0; } memset(vis,-1,sizeof(vis)); int x=400000,y=400000; q[x].push_back(y); int cnt=0; while(cnt<k){ cnt++; int tmpx=x,tmpy=y; int lx=tmpx,rx=tmpx,ly=tmpy,ry=tmpy; for(int i=1;i<=n;i++){ if(c[i]=='D') y--; else if(c[i]=='U') y++; else if(c[i]=='L') x--; else x++; q[x].push_back(y); lx=min(lx,x); rx=max(rx,x); ly=min(ly,y); ry=max(ry,y); } if((tmpx==x&&tmpy==y)||(lx>rx-tmpx)||(ly>ry-tmpy)) break; // cout<<tmpx<<" "<<tmpy<<" "<<x<<" "<<y<<endl; } // cout<<1<<endl; for(int i=0;i<=800000;i++){ if(q[i].empty()) continue; int siz=q[i].size(); for(int j=0;j<siz;j++){ int v=q[i][j]; // cout<<v<<endl; if(vis[v]!=i) ans++; vis[v]=i; } } ll tmp=0; for(int i=1;i<=n;i++){ if(c[i]=='D') y--; else if(c[i]=='U') y++; else if(c[i]=='L') x--; else x++; q[x].push_back(y); } for(int i=0;i<=800000;i++){ if(q[i].empty()) continue; int siz=q[i].size(); for(int j=0;j<siz;j++){ int v=q[i][j]; // cout<<v<<endl; if(vis[v]!=i+800001) tmp++; vis[v]=i+800001; } } printf("%lld",ans+(k-cnt)*(tmp-ans)); fclose(stdin); fclose(stdout); return 0; }