QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#231566#6422. Evil Coordinatebronze_REWA 10ms3808kbC++202.8kb2023-10-29 14:13:252023-10-29 14:13:25

Judging History

你现在查看的是最新测评结果

  • [2023-10-29 14:13:25]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3808kb
  • [2023-10-29 14:13:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed <<setprecision(2) << ans;
//inline ll read() {
//	ll ans=0,f=1;
//	char c=getchar();
//	while(c<'0' || c>'9') {
//		if(c=='-') f=-1;
//		c=getchar();
//	}
//	while(c>='0' && c<='9') {
//		ans=(ans<<1)+(ans<<3)+(c^48);
//		c=getchar();
//	}
//	return ans*f;
//}
//char F[200];
//inline void out(I_int x) {
//    if (x == 0) return (void) (putchar('0'));
//    I_int tmp = x > 0 ? x : -x;
//    if (x < 0) putchar('-');
//    int cnt = 0;
//    while (tmp > 0) {
//        F[cnt++] = tmp % 10 + '0';
//        tmp /= 10;
//    }
//    while (cnt > 0) putchar(F[--cnt]);
//    //cout<<" ";
//}
#define endl '\n'
const int N=1e5+5;
ll n,m;
ll cnt[4];
map<char,ll>mp;
ll now[4];
ll now2[4];
ll walk[2][4]={
        0,1,0,-1,
        1,0,-1,0,
};
bool dfs(ll x,ll y){
    if(n==x&&m==y)return 0;
    ll p=-1;
    for(int i=0;i<4;i++){
        if(now[i]<cnt[i]){
            p=i;break;
        }
    }
    if(p!=-1){
        now[p]++;
        ll dx=x+walk[0][p];
        ll dy=y+walk[1][p];
        return dfs(dx,dy);
    }
    return 1;
}
bool dfs2(ll x,ll y){
    if(n==x&&m==y)return 0;
    ll p=-1;
    for(int i=3;i>=0;i--){
        if(now2[i]<cnt[i]){
            p=i;break;
        }
    }
    if(p!=-1){
        now2[p]++;
        ll dx=x+walk[0][p];
        ll dy=y+walk[1][p];
        return dfs2(dx,dy);
    }
    return 1;
}
void solve(){
    cin>>n>>m;
    string s;
    cin>>s;
    ll len=s.size();
    for(int i=0;i<4;i++){
        cnt[i]=0;
    }
    for(int i=0;i<len;i++){
        cnt[mp[s[i]]]++;
    }
    ll y=cnt[0]-cnt[2];
    ll x=cnt[1]-cnt[3];
    if(x==n&&y==m){
        cout<<"Impossible\n";
        return ;
    }
    for(int i=0;i<4;i++){
        now[i]=0;
    }
    for(int i=0;i<4;i++){
        now2[i]=0;
    }
    if(dfs(0,0)){
        for(int i=1;i<=cnt[0];i++){
            cout<<'U';
        }
        for(int i=1;i<=cnt[1];i++){
            cout<<'R';
        }
        for(int i=1;i<=cnt[2];i++){
            cout<<'D';
        }
        for(int i=1;i<=cnt[3];i++){
            cout<<'L';
        }
        cout<<endl;
        return ;
    }
    else if(dfs2(0,0)){
        for(int i=1;i<=cnt[3];i++){
            cout<<'L';
        }
        for(int i=1;i<=cnt[2];i++){
            cout<<'D';
        }
        for(int i=1;i<=cnt[1];i++){
            cout<<'R';
        }
        for(int i=1;i<=cnt[0];i++){
            cout<<'U';
        }
        cout<<endl;
        return ;
    }
    cout<<"Impossible\n";
    return ;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int _=1;
    cin>>_;
    mp['U']=0;
    mp['R']=1;
    mp['D']=2;
    mp['L']=3;
    while(_--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3528kb

input:

5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU

output:

LLDRRUU
UUU
Impossible
Impossible
Impossible

result:

ok 5 cases

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 3808kb

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:

UURRDD
UUR
Impossible
Impossible
Impossible
UUUUUURRD
RRRRDDL
UD
Impossible
RRDDLLLL
URRDDDLL
Impossible
UURDDDDLL
LL
Impossible
UUURRDL
Impossible
Impossible
Impossible
LLLLLDDRRR
Impossible
RL
Impossible
Impossible
Impossible
Impossible
Impossible
LLLRRRRRUU
UDLLL
Impossible
UUUDDDL
UURRDD
Impossi...

result:

wrong answer case 946, participant does not find an answer but the jury does