QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850859 | #8355. T3 | Wanye# | 26 | 27ms | 4852kb | C++14 | 3.5kb | 2025-01-10 12:23:17 | 2025-01-10 12:23:18 |
Judging History
answer
#include<bits/stdc++.h>
#define N 305
using namespace std;
int n,u[N],d[N],l[N],r[N],i,j,sum,maps[N][N],id[N];
vector<pair<char,int> > ans;
bool cmp(int a,int b){return u[a]>u[b];}
inline void change(int pos,int type,int &tx,int &ty){
if(type==0){
for(int i=1;i<=n;i++){
if(!maps[i][pos]){
maps[i][pos]=1,tx=i,ty=pos;
return ;
}
}
}
if(type==1){
for(int i=n;i>=1;i--){
if(!maps[i][pos]){
maps[i][pos]=1,tx=i,ty=pos;
return ;
}
}
}
if(type==2){
for(int i=1;i<=n;i++){
if(!maps[pos][i]){
maps[pos][i]=1,tx=pos,ty=i;
return ;
}
}
}
if(type==3){
for(int i=n;i>=1;i--){
if(!maps[pos][i]){
maps[pos][i]=1,tx=pos,ty=i;
return ;
}
}
}
}
inline void dfs(int step){
if(step>sum){
for(int i=0;i<ans.size();i++) cout<<ans[i].first<<ans[i].second<<endl;
exit(0);
return ;
}
for(int i=1;i<=n;i++){
if(u[i]){
int tx = -1,ty = -1;
change(i,0,tx,ty);
if(tx==-1) continue;
u[i]--,ans.push_back(make_pair('U',i)),dfs(step+1);
u[i]++,ans.pop_back(),maps[tx][ty]=0;
}
}
for(int i=1;i<=n;i++){
if(d[i]){
int tx = -1,ty = -1;
change(i,1,tx,ty);
if(tx==-1) continue;
d[i]--,ans.push_back(make_pair('D',i)),dfs(step+1);
d[i]++,ans.pop_back(),maps[tx][ty]=0;
}
}
for(int i=1;i<=n;i++){
if(l[i]){
int tx = -1,ty = -1;
change(i,2,tx,ty);
if(tx==-1) continue;
l[i]--,ans.push_back(make_pair('L',i)),dfs(step+1);
l[i]++,ans.pop_back(),maps[tx][ty]=0;
}
}
for(int i=1;i<=n;i++){
if(r[i]){
int tx = -1,ty = -1;
change(i,3,tx,ty);
if(tx==-1) continue;
r[i]--,ans.push_back(make_pair('R',i)),dfs(step+1);
r[i]++,ans.pop_back(),maps[tx][ty]=0;
}
}
}
int t1 = 1,t2 = 1;
int main(){
ios::sync_with_stdio(false);
cin>>n;
for(i=1;i<=n;i++) cin>>u[i],sum+=u[i];
for(i=1;i<=n;i++) cin>>d[i],sum+=d[i],t1&=(d[i]==0);
for(i=1;i<=n;i++) cin>>l[i],sum+=l[i];
for(i=1;i<=n;i++) cin>>r[i],sum+=r[i],t2&=(r[i]==0);
if(n<=3){
dfs(1);
cout<<"NO"<<endl;
return 0;
}
if(t1&&t2){
int tx,ty;
for(i=1;i<=n+1;i++){
for(j=1;j<=n;j++) id[j]=j;
sort(id+1,id+n+1,cmp);
for(j=1;j<=n-l[i];j++){
if(u[id[j]]){
u[id[j]]--,tx=ty=-1;
change(id[j],0,tx,ty);
if(tx==-1){
cout<<"NO"<<endl;
return 0;
}
ans.push_back(make_pair('U',id[j]));
}
}
while(l[i]){
tx=ty=-1,l[i]--;
change(i,2,tx,ty);
if(tx==-1){
cout<<"NO"<<endl;
return 0;
}
ans.push_back(make_pair('L',i));
}
}
for(int i=0;i<ans.size();i++) cout<<ans[i].first<<ans[i].second<<endl;
return 0;
}
return 0;
}
详细
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 0ms
memory: 3656kb
input:
1 0 1 0 0
output:
D1
result:
ok OK
Test #2:
score: 11
Accepted
time: 0ms
memory: 3600kb
input:
3 0 0 1 1 1 1 0 1 0 1 2 1
output:
U3 D1 D3 L2 R2 R2 R3 D2 R1
result:
ok OK
Test #3:
score: 11
Accepted
time: 0ms
memory: 3672kb
input:
3 0 0 2 2 0 0 1 0 2 1 1 0
output:
U3 U3 D1 D1 L1 L3 L3 R1 R2
result:
ok OK
Test #4:
score: 11
Accepted
time: 0ms
memory: 3600kb
input:
3 0 0 0 0 1 0 1 0 0 1 3 3
output:
L1 R1 R2 R2 R2 R3 R3 D2 R3
result:
ok OK
Test #5:
score: 11
Accepted
time: 0ms
memory: 3672kb
input:
2 1 0 0 0 0 0 1 2
output:
U1 R1 R2 R2
result:
ok OK
Test #6:
score: 11
Accepted
time: 1ms
memory: 3696kb
input:
3 0 1 0 1 1 0 0 2 2 1 1 0
output:
U2 D2 L2 L2 L3 D1 L3 R1 R2
result:
ok OK
Test #7:
score: 11
Accepted
time: 0ms
memory: 3644kb
input:
2 0 0 2 0 1 0 1 0
output:
NO
result:
ok OK
Test #8:
score: 11
Accepted
time: 1ms
memory: 3596kb
input:
3 0 0 1 0 1 2 1 2 0 0 0 2
output:
U3 D3 D3 L1 L2 L2 R3 D2 R3
result:
ok OK
Test #9:
score: 11
Accepted
time: 0ms
memory: 3716kb
input:
2 1 1 0 0 0 0 2 0
output:
R1 U2 R1 U1
result:
ok OK
Test #10:
score: 11
Accepted
time: 0ms
memory: 3720kb
input:
3 2 0 1 1 1 1 1 1 0 0 0 1
output:
U1 U1 U3 D1 D2 L1 L2 R3 D3
result:
ok OK
Subtask #2:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 23ms
memory: 4620kb
input:
290 28 35 25 29 26 23 36 36 24 39 27 36 24 26 31 28 30 27 25 32 37 26 38 20 31 30 30 35 33 24 25 27 20 26 32 26 33 38 25 29 27 34 25 31 21 22 33 33 24 24 31 31 26 31 25 28 33 27 30 27 24 30 29 26 32 36 20 31 28 23 22 23 37 32 32 27 33 30 27 42 25 31 25 25 26 32 25 35 28 27 33 26 35 39 23 22 26 29 35...
output:
U183 U103 U232 U80 U272 U199 U226 U94 U213 U142 U10 U253 U280 U23 U38 U228 U73 U270 U131 U21 U246 U287 U66 U156 U278 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 ...
result:
ok OK
Test #12:
score: 15
Accepted
time: 20ms
memory: 4500kb
input:
277 53 51 63 63 45 55 51 56 53 55 59 51 54 60 48 59 62 45 51 55 61 55 57 51 52 61 47 59 61 52 50 51 44 59 61 59 45 47 66 55 71 59 55 66 63 56 50 56 55 53 53 51 58 55 48 60 67 54 58 49 48 52 63 52 61 66 52 64 57 61 50 61 58 58 48 56 76 56 49 55 57 52 44 62 59 55 50 47 53 52 69 51 56 55 64 52 49 59 55...
output:
U77 U236 U233 U41 U118 U91 U141 U174 U57 U39 U156 U66 U138 U164 U44 U262 U256 U221 U178 U239 U252 U275 U68 U264 U151 U95 U63 U223 U45 U183 U4 U167 U3 U145 U272 U224 U179 U276 U84 U165 U251 U222 U17 U268 U191 U220 U65 U72 U70 U237 U241 U274 U106 U35 U107 U29 U253 U26 U157 U21 U159 L1 L1 L1 L1 L1 L1 L...
result:
ok OK
Test #13:
score: 15
Accepted
time: 27ms
memory: 4520kb
input:
282 100 80 83 92 99 86 81 73 90 97 79 88 78 90 93 75 80 95 88 75 73 86 84 76 86 80 89 87 84 81 78 84 75 86 76 81 85 101 69 88 80 86 86 97 83 83 71 94 82 98 79 79 82 84 96 83 90 82 69 82 90 80 85 89 99 76 94 87 85 78 74 93 69 85 87 75 87 95 77 77 86 71 88 73 91 88 72 86 85 78 88 82 82 96 90 79 79 82 ...
output:
U228 U257 U194 U221 U38 U1 U158 U65 U5 U136 U50 U175 U10 U132 U154 U44 U189 U188 U94 U226 U55 U232 U208 U229 U177 U18 U185 U78 U254 U48 U223 U238 U67 U279 U199 U156 U165 U72 U15 U186 U150 U124 U118 U267 U258 U200 U171 U142 U4 U130 U167 U179 U180 U85 U266 U191 U9 U137 U148 U95 U102 U104 U110 U172 U16...
result:
ok OK
Test #14:
score: 15
Accepted
time: 24ms
memory: 4492kb
input:
287 98 119 107 123 117 117 121 115 127 128 115 133 111 117 110 96 91 113 110 110 114 105 114 109 98 108 120 129 113 103 99 119 104 123 100 111 117 118 125 126 124 123 114 105 121 108 128 107 124 126 118 116 114 125 119 103 111 119 129 120 121 109 113 108 109 122 119 119 116 119 113 122 124 117 126 1...
output:
U90 U246 U86 U12 U125 U123 U129 U285 U212 U251 U132 U76 U169 U170 U28 U59 U120 U263 U219 U282 U166 U193 U77 U10 U47 U113 U253 U202 U9 U121 U147 U216 U40 U50 U260 U75 U192 U98 U259 U39 U201 U200 U54 U73 U232 U237 U97 U91 U254 U208 U41 U49 U34 U155 U42 U203 U4 U122 U140 U258 U72 U101 U278 U79 U187 U66...
result:
ok OK
Test #15:
score: 15
Accepted
time: 16ms
memory: 4760kb
input:
265 144 139 128 130 134 135 140 122 129 143 129 132 132 135 120 135 146 138 129 132 111 123 154 138 128 124 125 135 134 141 130 127 146 123 131 133 122 142 140 146 140 141 128 119 133 134 137 148 123 134 142 127 124 137 130 132 136 128 142 126 134 126 138 137 133 141 119 137 146 137 136 126 141 127 ...
output:
U233 U23 U155 U187 U48 U103 U208 U145 U69 U196 U17 U175 U33 U132 U40 U140 U180 U154 U122 U1 U182 U158 U76 U249 U135 U10 U59 U265 U104 U38 U244 U51 U216 U207 U30 U246 U239 U78 U73 U66 U256 U42 U258 U100 U84 U39 U98 U41 U7 U156 U179 U88 U144 U210 U2 U202 U183 U92 U106 U114 U116 U121 U133 U153 U157 U18...
result:
ok OK
Test #16:
score: 15
Accepted
time: 5ms
memory: 4532kb
input:
286 235 245 221 241 222 248 226 244 228 207 234 229 241 261 209 231 222 203 225 230 256 224 236 243 222 246 235 243 247 234 241 255 232 234 211 258 249 238 252 237 240 221 244 223 212 240 259 261 235 264 238 205 224 223 238 222 199 225 222 217 236 220 212 204 230 253 221 214 195 216 219 239 220 233 ...
output:
NO
result:
ok OK
Test #17:
score: 15
Accepted
time: 19ms
memory: 4852kb
input:
268 187 183 183 184 179 189 177 173 176 186 183 182 187 175 185 218 176 191 195 183 182 197 182 195 195 183 185 193 205 182 192 179 183 176 190 185 195 182 189 189 196 184 194 184 199 189 190 190 191 201 197 196 190 186 186 197 188 190 188 171 191 186 181 188 170 188 176 188 190 190 187 181 190 187 ...
output:
U16 U193 U265 U29 U156 U257 U102 U88 U135 U255 U50 U128 U206 U172 U45 U149 U103 U85 U100 U253 U187 U198 U139 U22 U125 U123 U91 U51 U214 U56 U155 U52 U144 U146 U120 U41 U77 U152 U95 U248 U203 U211 U227 U37 U105 U262 U259 U79 U237 U236 U134 U19 U24 U25 U176 U174 U154 U157 U143 U268 U166 U190 U204 U230...
result:
ok OK
Test #18:
score: 15
Accepted
time: 19ms
memory: 4800kb
input:
261 204 204 215 204 209 212 197 219 216 205 210 208 216 205 207 203 217 203 209 208 211 207 210 213 200 206 213 208 214 205 200 220 206 210 213 209 206 207 207 201 212 213 212 206 225 210 196 221 205 217 202 206 212 205 196 218 205 209 194 206 199 204 219 204 222 208 208 210 195 208 215 211 201 206 ...
output:
U45 U197 U128 U149 U65 U189 U48 U228 U32 U144 U63 U167 U8 U230 U86 U257 U260 U184 U222 U56 U171 U140 U156 U203 U101 U50 U17 U90 U13 U87 U248 U9 U78 U71 U92 U154 U77 U261 U3 U217 U198 U107 U227 U129 U141 U234 U252 U29 U153 U194 U166 U255 U240 U80 U225 U35 U125 U219 U24 U210 U27 U146 U42 U187 U177 U22...
result:
ok OK
Test #19:
score: 15
Accepted
time: 19ms
memory: 4620kb
input:
281 251 252 254 244 260 254 254 245 251 258 258 253 256 263 249 256 252 253 247 253 250 249 243 248 264 246 246 264 242 256 245 258 257 251 252 247 252 259 251 253 252 246 255 261 255 249 251 250 255 255 257 246 251 254 250 255 256 258 256 257 254 254 252 254 263 258 262 253 255 250 250 254 245 264 ...
output:
U252 U189 U28 U25 U74 U14 U262 U248 U65 U104 U67 U169 U44 U121 U111 U5 U232 U251 U98 U90 U154 U38 U80 U83 U225 U236 U267 U141 U108 U166 U93 U274 U146 U88 U10 U58 U242 U131 U66 U245 U165 U11 U132 U110 U224 U32 U204 U100 U107 U230 U209 U188 U199 U187 U60 U206 U33 U263 U148 U51 U273 U16 U117 U202 U30 U...
result:
ok OK
Test #20:
score: 15
Accepted
time: 7ms
memory: 4180kb
input:
253 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 L1 ...
result:
ok OK
Subtask #3:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 0ms
memory: 3676kb
input:
289 30 29 31 35 25 34 26 28 25 25 44 26 33 30 27 30 33 37 26 27 43 28 28 40 31 36 21 26 35 28 31 29 41 25 30 25 35 28 38 24 26 26 24 24 25 27 18 44 31 24 37 28 26 31 27 32 29 24 24 32 20 35 26 39 30 28 33 30 27 28 37 35 29 22 27 27 31 30 25 31 31 22 30 34 33 31 30 29 41 26 38 36 28 28 21 22 31 34 32...
output:
result:
wrong output format Unexpected end of file - token expected
Subtask #4:
score: 0
Wrong Answer
Test #31:
score: 25
Accepted
time: 0ms
memory: 3664kb
input:
1 1 0 0 0
output:
U1
result:
ok OK
Test #32:
score: 25
Accepted
time: 0ms
memory: 3600kb
input:
2 0 1 0 1 0 0 1 1
output:
U2 D2 R1 R2
result:
ok OK
Test #33:
score: 25
Accepted
time: 0ms
memory: 3656kb
input:
3 0 1 0 0 1 2 2 1 0 0 1 1
output:
U2 D2 D3 D3 L1 L1 L2 R2 R3
result:
ok OK
Test #34:
score: 0
Wrong Answer
time: 0ms
memory: 3676kb
input:
9 2 1 3 4 3 3 2 3 2 2 4 2 1 1 2 4 2 2 4 0 3 3 1 1 2 3 2 0 2 2 2 2 4 1 2 4
output:
result:
wrong output format Unexpected end of file - token expected
Subtask #5:
score: 0
Wrong Answer
Test #77:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
299 72 66 62 73 80 85 70 93 79 88 77 72 67 70 73 84 77 62 80 77 88 63 69 76 73 91 64 76 75 65 74 71 71 68 81 80 74 77 69 75 73 87 90 82 86 79 76 83 69 72 73 73 75 78 76 80 66 76 67 75 72 71 77 63 80 68 82 63 74 67 74 72 73 76 71 72 66 78 74 65 69 80 76 71 72 74 77 70 85 60 65 89 66 64 77 63 78 82 80...
output:
result:
wrong output format Unexpected end of file - token expected