QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393986 | #2833. Hamilton | zyz07 | WA | 1ms | 3904kb | C++17 | 2.8kb | 2024-04-19 20:06:00 | 2024-04-19 20:06:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=2005;
int n;
char col[N][N];
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
while(cin>>n){
For(i,1,n){
string s;
cin>>s;
For(j,1,i-1){
col[i][j]=col[j][i]="RB"[s[j-1]-'0'];
}
}
if(n<=2){
For(i,1,n){
cout<<n<<'\n';
cout<<i<<' ';
For(j,1,n){
if(j!=i){
cout<<j<<' ';
}
}
cout<<'\n';
}
continue;
}
For(i,1,n){
deque<int> red,blue;
vector<int> poi;
For(j,1,n){
if(j!=i){
poi.push_back(j);
}
}
switch((col[i][poi[1]]=='R')*2+(col[poi[0]][poi[1]]=='R')){
case 3:{
red={i,poi[1],poi[0]};
break;
}
case 2:{
red={i,poi[1]};
blue={poi[0]};
break;
}
case 1:{
red={poi[0],poi[1]};
blue={i};
break;
}
default:{
red={i};
blue={poi[1],poi[0]};
}
}
For(j,2,n-2){
int u=poi[j];
if(red.size()==1){
if(red[0]!=i){
if(col[u][red[0]]=='R'){
red.push_front(u);
}else{
blue.push_front(red[0]);
red.back()=u;
}
}else{
if(col[u][blue.back()]=='B'){
blue.push_back(u);
}else{
blue.push_front(red[0]);
red={u,blue.back()};
blue.pop_back();
reverse(range(blue));
}
}
}else if(!blue.size()){
if(col[u][red.back()]=='R'){
red.push_back(u);
}else{
blue.push_back(u);
}
}else{
int u1=red.end()[-2],u2=red.back(),u3=blue[0];
switch((col[u][u1]=='R')*2+(col[u][u2]=='R')){
case 3:{
red.back()=u;
red.push_back(u2);
break;
}
case 2:{
red.back()=u;
blue.push_front(u2);
break;
}
case 1:{
if(col[u][u3]=='R'){
blue.pop_front();
red.push_back(u);
red.push_back(u3);
}else{
red.push_back(u);
}
break;
}
default:{
red.pop_back();
blue.push_front(u2);
blue.push_front(u);
}
}
}
if(red[0]!=i&&(!blue.size()||blue.back()!=i)){
assert(red.back()==i&&!blue.size());
reverse(range(red));
}
}
if(red[0]==i){
if(blue.size()&&col[i][blue.back()]!='B'){
continue;
}
for(int u:red) cout<<u<<' ';
for(int u:blue) cout<<u<<' ';
}else{
reverse(range(blue));
reverse(range(red));
if(red.size()&&col[i][red.back()]!='R'){
continue;
}
for(int u:blue) cout<<u<<' ';
for(int u:red) cout<<u<<' ';
}
cout<<'\n';
break;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3904kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
1 3 2 1 3 2 4
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
1 3 2 1 3 2 2 3 1 1 3 2
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 0000 0000 0000 0000 4 0000 0001 0000 0100 4 0100 1010 0100 0000 4 0111 1000 1000 1000 4 0010 0011 1101 0110 4 0111 1011 1100 1100 4 0111 1011 1101 1110 4 0000 0011 0101 0110 4 0101 1010 0100 1000 4 0011 0011 1100 1100 4 0010 0001 1000 0100
output:
1 3 2 4 2 3 1 4 1 4 3 2 2 4 3 1 4 2 3 1 1 3 2 4 1 3 2 4 2 3 4 1 1 3 4 2 1 3 2 4 1 4 3 2
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 00000 00000 00000 00000 00000 5 00001 00000 00000 00000 10000 5 00010 00010 00000 11000 00000 5 00000 00001 00001 00001 01110 5 00001 00001 00001 00001 11110 5 00101 00100 11011 00100 10100 5 01111 10011 10000 11000 11000 5 00011 00011 00011 11101 11110 5 01101 10111 11001 01001 11110 5 00111 0011...
output:
1 3 2 4 5 1 3 2 4 5 1 3 5 2 4 2 3 1 4 5 1 3 2 4 5 1 3 2 5 4 2 3 5 4 1 1 3 5 2 4 1 3 2 4 5 1 3 2 4 5 1 3 2 4 5 2 3 5 4 1 1 4 3 2 5 1 3 4 2 5 2 4 5 3 1 2 3 4 5 1 2 3 1 4 5 1 3 2 5 4 3 2 5 1 4 2 3 1 4 5 1 3 2 4 5 2 3 4 1 5 3 5 4 2 1 1 3 5 4 2 4 2 3 1 5 1 4 5 3 2 2 3 1 4 5 1 4...
result:
ok 34 cases.
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 3680kb
input:
6 000000 000000 000000 000000 000000 000000 6 000000 000000 000001 000000 000000 001000 6 010000 100100 000000 010000 000000 000000 6 000100 000000 000100 101010 000100 000000 6 000100 000000 000100 101011 000100 000100 6 001000 001000 110111 001000 001000 001000 6 001100 000100 100100 111011 000100...
output:
1 3 2 4 5 6 1 3 2 4 5 6 2 3 1 4 5 6 3 2 5 6 1 4 3 2 5 6 1 4 1 3 2 6 5 4 1 3 4 2 6 5 1 3 2 6 5 4 1 3 2 6 5 4 1 3 2 5 4 6 2 3 1 5 4 6 4 2 1 5 3 6 1 3 2 4 6 5 3 2 1 4 5 6 1 3 2 4 5 6 1 3 2 4 5 6 1 5 4 3 2 6 1 3 2 6 4 5 1 3 2 4 5 6 5 2 1 6 3 4 2 3 1 4 6 5 4 6 5 3 2 1 1 3 2 5 6 4 1...
result:
wrong answer case #113: found 5 indices