QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#423815 | #5878. Ace in the Hole | Dark_night | 42 ✓ | 5ms | 3724kb | C++14 | 1.2kb | 2024-05-28 17:17:47 | 2024-05-28 17:17:47 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int _,n,a[305];
int p[305],v[305];
inline void sol()
{
cin>>n;
for(int i=1;i<=n;i++)
a[i]=0,p[i]=v[i]=i;
for(int i=1;i<=n;i++)
{
int b;
cin>>b;
int pos=0;
for(int j=1;j<=n-i+1;j++)
{
if(p[j]==b)
pos=j;
}
if(pos!=n-i+1)
{
a[p[pos]]=v[pos+1];
for(int j=pos;j<=n-i+1;j++)
p[j]=p[j+1];
for(int j=pos+1;j<=n-i+1;j++)
v[j]=v[j+1];
continue;
}
bool f=0;
for(int j=1;j<p[pos];j++)
{
if(v[pos-1]<a[j]&&a[j]<v[pos])
f=1;
}
if(f||i>n-2)
a[p[pos]]=v[pos];
else
a[p[pos]]=v[pos-1],v[pos-1]=v[pos];
}
for(int i=1;i<=n;i++)
cout<<a[i]<<" \n"[i==n];
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>_;
for(int i=1;i<=_;i++)
{
cout<<"Case #"<<i<<": ";
sol();
}
return 0;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 1ms
memory: 3704kb
input:
100 3 2 1 3 1 1 3 3 2 1 6 2 3 4 1 6 5 8 7 8 4 2 5 1 6 3 8 5 1 7 6 4 2 8 3 6 2 1 4 3 5 6 8 7 1 4 2 8 3 5 6 8 7 5 8 6 4 3 2 1 8 8 7 6 4 5 3 2 1 8 7 6 8 5 4 3 2 1 6 3 6 1 4 5 2 8 7 6 3 8 5 2 4 1 6 2 1 4 5 3 6 8 6 5 4 3 2 7 1 8 8 7 6 4 2 8 5 3 1 8 6 2 8 5 3 4 7 1 8 7 5 1 8 6 4 3 2 8 7 4 6 2 5 8 1 3 8 2 ...
output:
Case #1: 2 3 1 Case #2: 1 Case #3: 1 3 2 Case #4: 2 3 4 5 1 6 Case #5: 2 3 1 5 7 4 8 6 Case #6: 2 3 1 5 6 7 8 4 Case #7: 2 3 4 5 6 1 Case #8: 2 3 4 5 7 1 8 6 Case #9: 1 5 2 3 6 4 8 7 Case #10: 1 4 2 8 3 5 6 7 Case #11: 1 6 2 3 4 7 8 5 Case #12: 2 1 4 6 3 5 Case #13: 1 3 4 2 6 7 8 5 Case #14: 2 3 4 5...
result:
ok 100 lines
Subtask #2:
score: 22
Accepted
Test #2:
score: 22
Accepted
time: 5ms
memory: 3724kb
input:
100 3 2 1 3 1 1 3 3 2 1 300 106 240 43 265 1 217 207 149 51 112 130 62 47 242 158 78 178 180 39 165 164 31 84 299 160 289 108 126 193 234 24 13 119 6 42 29 270 281 26 148 252 37 196 151 44 243 188 96 224 27 209 210 297 227 272 225 69 283 189 278 9 4 121 290 30 293 269 291 268 48 11 294 195 134 7 232...
output:
Case #1: 2 3 1 Case #2: 1 Case #3: 1 3 2 Case #4: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 ...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed