QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408259 | #6699. Wandering Robot | _Dusker# | AC ✓ | 3ms | 3840kb | C++20 | 874b | 2024-05-09 22:03:08 | 2024-05-09 22:03:10 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010;
int a[N];
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;
cin >> T;
while(T --)
{
int sum = 0;
int n,k;
cin>>n>>k;
string s;
cin>>s;
int maxn=-1e9,xx=0,yy=0;
for (int i=0;i<s.size();i++)
{
if (s[i]=='R') xx++;
else if (s[i]=='L') xx--;
else if (s[i]=='U') yy++;
else yy--;
if (abs(yy)+abs(xx)>maxn) maxn=abs(yy)+abs(xx);
}
//cout<<xx<<" "<<yy<<endl;
int ans1=maxn,ans2=0;
int x=xx*(k-1),y=yy*(k-1);
//cout<<x<<" "<<y<<endl;
maxn=abs(x)+abs(y);
for (int i=0;i<s.size();i++)
{
if (s[i]=='R') x++;
else if (s[i]=='L') x--;
else if (s[i]=='U') y++;
else y--;
if (abs(x)+abs(y)>maxn) maxn=abs(x)+abs(y);
}
cout<<max(ans1,maxn)<<endl;
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3520kb
input:
2 3 3 RUL 1 1000000000 D
output:
4 1000000000
result:
ok 2 number(s): "4 1000000000"
Test #2:
score: 0
Accepted
time: 3ms
memory: 3840kb
input:
10307 33 374631889 RUDUUDLDDUULULDRDDRRRRDDDLRURULDL 9 40711970 UUDLRDRDD 3 111498848 LRL 14 804199874 LRRLLRULRUURUU 44 936610223 ULDRUULRRDLRRLRLRLRDUDDUDDUUDDLRUUDRUURLULUD 15 669124042 RUULRLDDULUDRDR 47 500758328 LRULULLLLUDURLRRDLDDLUUDURUDDLLLLDRLULURDULRDLU 18 581526184 DLLUDUUULUDULULRLR 47...
output:
1873159447 122135910 111498848 4825199244 3746440893 669124044 5508341608 4652209473 5606278385 8301130033 3707957881 2821884978 463006533 1581485530 881213211 236693627 816980016 4406947601 1057578188 1455154265 4107693543 5705944723 3424946932 1154164548 4496114815 3733695266 6323077602 2262619671...
result:
ok 10307 numbers