QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#407664 | #6422. Evil Coordinate | xiaole | WA | 7ms | 3708kb | C++23 | 2.0kb | 2024-05-09 08:45:42 | 2024-05-09 08:45:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;using ll = long long;using PLL = pair<ll,ll>;
const ll MAX = 1e18;const ll MIN = -1e18;const ll INF=0x3f3f3f3f;
const ll Q = 2e5+9;const ll MOD = 1e9 + 7;
pair<ll,ll> f[5];ll n,m;
bool check(){
ll x=0,y=0;
if(x==n and y==m) return false;
for (ll i = 1; i <= 4; i++)
{
ll now=0;
while(f[i].second==1 and now<f[i].first) {
x++,now++;
if(x==n and y==m) return false;
}
while(f[i].second==-1 and now<f[i].first) {
x--,now++;
if(x==n and y==m) return false;
}
while(f[i].second==2 and now<f[i].first) {
y--,now++;
if(x==n and y==m) return false;
}
while(f[i].second==-2 and now<f[i].first) {
y++,now++;
if(x==n and y==m) return false;
}
}
return true;
}
void solve(){
cin>>n>>m;
string s;cin>>s;
f[1].first=0;
f[2].first=0;
f[3].first=0;
f[4].first=0;
f[1].second=-1;
f[2].second=1;
f[3].second=-2;
f[4].second=2;
for (ll i = 0; i < s.size(); i++)
{
if(s[i]=='L') f[1].first++;
if(s[i]=='R') f[2].first++;
if(s[i]=='U') f[3].first++;
if(s[i]=='D') f[4].first++;
}
do
{
if(check()){
for (ll i = 1; i <= 4; i++)
{
ll now=0;
while(f[i].second==1 and now<f[i].first) {
cout<<'R';now++;
}
while(f[i].second==-1 and now<f[i].first) {
cout<<'L';now++;
}
while(f[i].second==2 and now<f[i].first) {
cout<<'D';now++;
}
while(f[i].second==-2 and now<f[i].first) {
cout<<'U';now++;
}
}
cout<<"\n";
return;
}
} while (next_permutation(f+1,f+5));
cout<<"Impossible\n";
}
int main(){
ios;ll _=1;cin>>_;
while (_--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3696kb
input:
5 1 1 RURULLD 0 5 UUU 0 3 UUU 0 2 UUU 0 0 UUU
output:
LLRRUUD UUU Impossible Impossible Impossible
result:
ok 5 cases
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 3708kb
input:
11109 6 0 RUDUDR 2 0 URU 0 0 UDRU 0 0 R -1 1 LDUUDDRUUL -1 5 RRUUUDUUU -8 4 RRDRLDR 2 0 UD 0 0 UUDD 3 -2 LDDLLLRR 3 -2 LDRURLDD 1 0 RRL -1 0 DUDDLLRDU -4 0 LL -1 -1 DLRLDLUDUR 1 4 URDULUR 0 0 DDUUDUDDDD 0 2 UU 1 0 RRULD 0 -2 LDLRLLDRRL 0 1 RLRLLRLUR -3 0 RL 0 0 D 0 0 L 0 0 DDLRRUDRUD 0 0 DULU 2 0 RR...
output:
RRUUDD RUU Impossible Impossible Impossible RRUUUUUUD LRRRRDD UD Impossible LLLLRRDD LLRRUDDD Impossible DDDDRUULL LL Impossible LRRUUUD Impossible Impossible Impossible LLLLLRRRDD Impossible LR Impossible Impossible Impossible Impossible Impossible LLLRRRRRUU LLLUD Impossible LUUUDDD RRUUDD Impossi...
result:
wrong answer case 48, participant does not find an answer but the jury does