QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469545 | #6699. Wandering Robot | zzisjtu# | WA | 10ms | 3784kb | C++23 | 1.4kb | 2024-07-09 20:05:23 | 2024-07-09 20:05:24 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
int abss(int a){
if(a>=0ll)return a;
return 0ll-a;
}
pair<int,int> maxx(pair<int,int>a,pair<int,int>b){
if(abss(a.first)+abss(a.second)>=abss(b.first)+abss(b.second))return a;
return b;
}
void solve()
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
pair<int,int>a={0,0},b={0,0};
for(int i=0;i<n;i++){
if(s[i]=='U')a.second+=1;
else if(s[i]=='D')a.second-=1;
else if(s[i]=='L')a.first-=1;
else if(s[i]=='R')a.first+=1;
b=maxx(a,b);
}
int ans=1ll*abss(b.first)+1ll*abss(b.second);
int res=0;
if(a.second!=b.second||a.first!=b.first){
res=1ll*abss(b.first)+1ll*abss(b.second);
res-=1ll*abss(a.first)+1ll*abss(a.second);
res*=1ll*(k-1);
}
else{
res=1ll*ans*(k-1);
}
cout<<ans+res<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
input:
2 3 3 RUL 1 1000000000 D
output:
4 1000000000
result:
ok 2 number(s): "4 1000000000"
Test #2:
score: -100
Wrong Answer
time: 10ms
memory: 3664kb
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:
749263783 122135910 111498848 4825199244 936610227 1338248085 5508341608 581526192 800896919 2490339019 926989474 3762513307 463006533 1581485530 881213211 236693627 816980016 550868458 1057578188 3637885652 2053846776 633993867 684989396 1154164548 749352475 574414669 1580769408 1292925531 12120405...
result:
wrong answer 1st numbers differ - expected: '1873159447', found: '749263783'