QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#485165 | #6699. Wandering Robot | Ink_bai | WA | 0ms | 3564kb | C++14 | 1.9kb | 2024-07-20 14:36:12 | 2024-07-20 14:36:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int ppox(int x, int y)
{
if(x >= 0 && y >= 0) return x + y;
else if(x >= 0 && y < 0) return x - y;
else if(x < 0 && y >= 0) return y - x;
else return 0 - x - y;
}
int main()
{
int n;
cin >> n;
while(n--)
{
int posx = 0, posy = 0;
int a, b;
cin >> a >> b;
string s;
cin >> s;
vector<int> vx, vy;
for(int i=0; i<s.size(); i++)
{
if(s[i] == 'U') posy++;
else if(s[i] == 'D') posy--;
else if(s[i] == 'L') posx--;
else if(s[i] == 'R') posx++;
vx.push_back(posx);
vy.push_back(posy);
}
int max = 0;
if(posx >= 0 && posy >= 0)
{
for(int i=0; i<s.size(); i++)
{
if(vx[i] >= 0 && vy[i] >= 0)
if(ppox(vx[i], vy[i]) > max) max = ppox(vx[i], vy[i]);
}
}
if(posx >= 0 && posy <= 0)
{
for(int i=0; i<s.size(); i++)
{
if(vx[i] >= 0 && vy[i] <= 0)
if(ppox(vx[i], vy[i]) > max) max = ppox(vx[i], vy[i]);
}
}
if(posx <= 0 && posy >= 0)
{
for(int i=0; i<s.size(); i++)
{
if(vx[i] <= 0 && vy[i] >= 0)
if(ppox(vx[i], vy[i]) > max) max = ppox(vx[i], vy[i]);
}
}
if(posx <= 0 && posy <= 0)
{
for(int i=0; i<s.size(); i++)
{
if(vx[i] <= 0 && vy[i] <= 0)
if(ppox(vx[i], vy[i]) > max) max = ppox(vx[i], vy[i]);
}
}
int temp = abs(posx) + abs(posy);
cout << temp << " " << max << endl;
cout << temp * (b-1) + max << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
2 3 3 RUL 1 1000000000 D
output:
1 2 4 1 1 1000000000
result:
wrong answer 1st numbers differ - expected: '4', found: '1'