QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469530 | #6699. Wandering Robot | zzisjtu# | WA | 11ms | 3784kb | C++23 | 1.5kb | 2024-07-09 19:59:47 | 2024-07-09 19:59:48 |
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;
pair<int,int> maxx(pair<int,int>a,pair<int,int>b){
if(labs(a.first)+labs(a.second)>=labs(b.first)+labs(b.second))return a;
return b;
}
int abss(int a){
if(a>=0ll)return a;
return 0ll-a;
}
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);
// if(a!=b)ans+=(1ll*labs(b.first)+1ll*labs(b.second)
// -(labs(a.first)+labs(a.second)))*1ll*(k-1);
// else ans=1ll*ans*k;
int res=0;
if(a!=b){
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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: 11ms
memory: 3784kb
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'