QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667102 | #7158. Carnival General | Warinchai_s# | 40 | 22ms | 17528kb | C++14 | 1.8kb | 2024-10-22 21:03:28 | 2024-10-22 21:03:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int r[1005][1005];
int no[1005][1005];
vector<int>adj[1005];
vector<int>rv[1005];
int in[1005];
int vis[1005];
int bf[1005];
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
int st=0;
int cnt=0;
int n;
void dfs(int u,int p=-1){
bf[u]=p;
st=u;
cnt++;
int mn=1e4,id=-1;
for(auto x:adj[u])if(x!=p)if(!vis[x]&&in[x]<mn)mn=in[x],id=x;
if(id==-1){
assert(cnt==n);
return;
}
vis[id]=1;
dfs(id,u);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=0;i<n;i++){
//cerr<<"i:"<<i<<"\n";
for(int j=0;j<i;j++){
cin>>r[i][j];
if(j>(i-1)/2){
no[i][r[i][j]]=1;
no[r[i][j]][i]=1;
//cerr<<"no:"<<i<<' '<<r[i][j]<<"\n";
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)continue;
if(!no[i][j])adj[i].push_back(j),adj[j].push_back(i),in[j]++,in[i]++;
}
}
for(int i=0;i<n;i++){
pq.push({in[i],i});
}
auto [a,b]=pq.top();
pq.pop();
vis[b]=1;
dfs(b);
int x=0;
vector<int>v;
while(st!=-1){
//cout<<st<<" ";
v.push_back(st);
st=bf[st];
}
assert(v.size()==n);
for(int i=1;i<n-1;i++){
assert(no[v[i]][v[i-1]]==0);
assert(no[v[i-1]][v[i]]==0);
assert(no[v[i+1]][v[i]]==0);
assert(no[v[i]][v[i+1]]==0);
}
assert(no[v[0]][v[1]]==0);
assert(no[v[n-2]][v[n-1]]==0);
map<int,int>mp;
for(auto x:v){
assert(mp[x]==0);
mp[x]++;
}
//assert(0);
for(auto x:v)cout<<x<<" ";
}
详细
Subtask #1:
score: 11
Accepted
Test #1:
score: 11
Accepted
time: 1ms
memory: 5704kb
input:
2 0
output:
1 0
result:
ok correct
Test #2:
score: 11
Accepted
time: 1ms
memory: 6164kb
input:
99 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 11 10 9 8 7 6 5 4 3 2 1 0 12 11 10 9 8 7 6 5 4 3 2 1 0 13 12 11 10 9 8 7 6 5 4 3 2 1 0 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 16 1...
output:
49 51 50 48 53 52 47 55 54 57 56 46 59 58 45 61 60 63 62 44 65 64 43 67 66 69 68 42 71 70 41 73 72 75 74 40 77 76 79 81 80 83 82 85 84 87 86 89 88 91 90 93 92 95 94 97 96 98 78 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
result:
ok correct
Test #3:
score: 11
Accepted
time: 22ms
memory: 17528kb
input:
1000 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 10 9 8 7 6 5 4 3 2 1 0 11 10 9 8 7 6 5 4 3 2 1 0 12 11 10 9 8 7 6 5 4 3 2 1 0 13 12 11 10 9 8 7 6 5 4 3 2 1 0 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 16...
output:
499 501 500 503 502 498 505 504 497 507 506 509 508 496 511 510 495 513 512 515 514 494 517 516 493 519 518 521 520 492 523 522 491 525 524 527 526 490 529 528 489 531 530 533 532 488 535 534 487 537 536 539 538 486 541 540 485 543 542 545 544 484 547 546 483 549 548 551 550 482 553 552 481 555 554 ...
result:
ok correct
Test #4:
score: 11
Accepted
time: 0ms
memory: 5664kb
input:
8 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0
output:
3 5 7 6 4 2 1 0
result:
ok correct
Test #5:
score: 11
Accepted
time: 0ms
memory: 5640kb
input:
6 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0
output:
3 5 4 2 1 0
result:
ok correct
Subtask #2:
score: 0
Runtime Error
Test #6:
score: 23
Accepted
time: 1ms
memory: 5916kb
input:
2 0
output:
1 0
result:
ok correct
Test #7:
score: 0
Runtime Error
input:
99 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 13 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 ...
output:
result:
Subtask #3:
score: 29
Accepted
Test #12:
score: 29
Accepted
time: 1ms
memory: 5628kb
input:
2 0
output:
1 0
result:
ok correct
Test #13:
score: 29
Accepted
time: 1ms
memory: 5748kb
input:
8 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0
output:
3 5 7 6 4 2 1 0
result:
ok correct
Test #14:
score: 29
Accepted
time: 1ms
memory: 5960kb
input:
8 0 0 1 0 1 2 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6
output:
6 0 5 2 7 3 1 4
result:
ok correct
Test #15:
score: 29
Accepted
time: 1ms
memory: 5660kb
input:
8 0 0 1 0 1 2 2 1 0 3 4 3 0 2 1 4 3 0 5 2 1 6 5 2 1 4 0 3
output:
0 6 7 5 3 1 4 2
result:
ok correct
Test #16:
score: 29
Accepted
time: 1ms
memory: 5656kb
input:
8 0 1 0 0 1 2 3 2 1 0 0 1 2 3 4 5 4 3 2 1 0 0 1 2 3 4 5 6
output:
3 1 2 7 0 5 6 4
result:
ok correct
Test #17:
score: 29
Accepted
time: 1ms
memory: 5864kb
input:
3 0 0 1
output:
2 0 1
result:
ok correct
Test #18:
score: 29
Accepted
time: 1ms
memory: 5872kb
input:
5 0 1 0 0 2 1 1 3 2 0
output:
4 3 2 1 0
result:
ok correct
Test #19:
score: 29
Accepted
time: 1ms
memory: 5664kb
input:
6 0 0 1 0 1 2 0 2 1 3 0 2 3 4 1
output:
0 4 2 5 3 1
result:
ok correct
Test #20:
score: 29
Accepted
time: 1ms
memory: 5680kb
input:
7 0 1 0 2 0 1 2 0 1 3 0 1 4 2 3 3 2 4 0 5 1
output:
4 2 6 3 0 5 1
result:
ok correct
Test #21:
score: 29
Accepted
time: 1ms
memory: 5732kb
input:
8 0 1 0 0 1 2 3 2 0 1 3 1 0 4 2 4 2 0 3 5 1 6 4 3 1 5 2 0
output:
3 7 1 5 0 6 4 2
result:
ok correct
Test #22:
score: 29
Accepted
time: 1ms
memory: 5736kb
input:
8 0 0 1 2 1 0 3 0 2 1 4 0 3 1 2 4 0 2 5 3 1 4 5 1 2 0 6 3
output:
4 7 5 0 6 2 3 1
result:
ok correct
Test #23:
score: 29
Accepted
time: 1ms
memory: 5732kb
input:
8 0 0 1 0 1 2 3 2 1 0 4 3 2 1 0 5 4 3 2 1 0 6 5 4 3 2 1 0
output:
3 5 7 6 4 2 0 1
result:
ok correct
Test #24:
score: 29
Accepted
time: 1ms
memory: 5912kb
input:
8 0 1 0 2 1 0 0 1 2 3 0 1 2 3 4 0 1 2 3 4 5 0 1 2 3 4 5 6
output:
6 1 7 3 2 5 0 4
result:
ok correct
Test #25:
score: 29
Accepted
time: 1ms
memory: 5728kb
input:
8 0 1 0 1 0 2 1 3 0 2 1 3 0 2 4 1 3 5 0 2 4 1 3 5 0 2 4 6
output:
7 0 5 6 3 4 1 2
result:
ok correct
Test #26:
score: 29
Accepted
time: 1ms
memory: 5952kb
input:
6 0 1 0 2 1 0 3 2 1 0 4 3 2 1 0
output:
3 5 4 2 1 0
result:
ok correct
Test #27:
score: 29
Accepted
time: 1ms
memory: 5740kb
input:
5 0 0 1 0 1 2 0 1 2 3
output:
4 1 3 0 2
result:
ok correct
Test #28:
score: 29
Accepted
time: 1ms
memory: 5732kb
input:
4 0 1 0 0 2 1
output:
3 2 1 0
result:
ok correct
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%