QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#469488 | #6699. Wandering Robot | zzisjtu# | WA | 10ms | 3780kb | C++23 | 1.3kb | 2024-07-09 19:41:32 | 2024-07-09 19:41:32 |
Judging History
answer
#include<bits/stdc++.h>
#define ll 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<ll,ll> maxx(pair<ll,ll>a,pair<ll,ll>b){
if(labs(a.first)+labs(a.second)>labs(b.first)+labs(b.second))return a;
return b;
}
void solve()
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
pair<ll,ll>a={0,0},b={0,0};
for(int i=0;i<s.size();i++){
if(s[i]=='U')a.first+=1;
else if(s[i]=='D')a.first-=1;
else if(s[i]=='L')a.second-=1;
else if(s[i]=='R')a.second+=1;
b=maxx(a,b);
// cout<<b.first<<" "<<b.second<<endl;
}
ll ans=1ll*labs(b.first)+1ll*labs(b.second);
if(a!=b)ans+=(1ll*labs(b.first)+1ll*labs(b.second)-(labs(a.first)+labs(a.second)))*k-1;
else ans=1ll*ans*k;
cout<<ans<<endl;
}
int 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: 0ms
memory: 3552kb
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: 3780kb
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:
749263784 122135910 111498848 4825199244 936610227 1338248086 5508341608 581526192 800896919 2490339021 926989474 3762513310 463006533 1581485531 881213211 236693627 816980016 550868458 1 3637885656 2053846778 633993867 684989397 5 749352475 574414670 1580769409 1292925534 1212040571 2073657229 3568...
result:
wrong answer 1st numbers differ - expected: '1873159447', found: '749263784'