QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#22041#2833. HamiltonLFCodeAC ✓31ms9584kbC++142.4kb2022-03-09 08:28:162022-04-30 00:42:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 00:42:47]
  • 评测
  • 测评结果:AC
  • 用时:31ms
  • 内存:9584kb
  • [2022-03-09 08:28:16]
  • 提交

answer

#include<bits/stdc++.h>
#include<cstdio>
#include<cctype>
#define ll long long
#define PI pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ui unsigned int
#define pb push_back
#define llu long long unsigned
using namespace std;
const int MB=1<<20;
struct FastIO{
	char ib[MB+100],*p,*q;
	char ob[MB+100],*r,stk[128];
	int tp;
	FastIO(){p=q=ib,r=ob,tp=0;}
	~FastIO(){fwrite(ob,1,r-ob,stdout);}
	char read_char(){if(p==q){p=ib,q=ib+fread(ib,1,MB,stdin);if(p==q)return 0;}return *p++;}
	template<typename T>
	void read_int(T& x){char c=read_char(),l=0;for(x=0;!isdigit(c);c=read_char())l=c;for(;isdigit(c);c=read_char())x=x*10-'0'+c;if(l=='-')x=-x;}
	void write_char(char c){if(r-ob==MB)r=ob,fwrite(ob,1,MB,stdout);*r++=c;}
	template<typename T>
	void write_int(T x){if(x<0)write_char('-'),x=-x;do stk[++tp]=x%10+'0';while(x/=10);while(tp)write_char(stk[tp--]);}
}IO;
//IO.read_int(a);c=IO.read_char();IO.write_int(a);//IO.write_char(c);
const int N=2010;
int T,n,a[N];
char ch[N][N];
int ovo[N*2];
int front,back;
int main(){
//	scanf("%d",&T);
	while(scanf("%d",&n)!=EOF){
		memset(ovo,0,sizeof(ovo));
		for(int i=1;i<=n;i++){
			scanf("%s",ch[i]+1);
		}
		if(ch[1][2]=='1'){
			front=N,back=N+1;
			ovo[front]=1;ovo[back]=2;
		}
		else{
			front=N-1,back=N;
			ovo[front]=1;ovo[back]=2;
		}
		int mid=N;
		for(int i=3;i<=n;i++){
			if(ch[ovo[mid]][i]=='1'){
				for(int io=1;io<=mid-1;io++){
					ovo[io]=ovo[io+1];
				}
				ovo[mid-1]=i;
				front--;
				int bef=ovo[mid-2];
				if(front==mid-1)bef=ovo[back];
				if(ch[ovo[mid-1]][bef]=='1'){
					if(bef==ovo[back]){
						front++;
						back++;
						ovo[back]=i;
					}
					else{
						mid-=2;
					}
				}
				else{
					if(bef==ovo[back]){
						front--;
						ovo[front]=ovo[back];
						back--;
						mid--;
					}
					else{
						mid--;
					}
				}
			}
			else{
				for(int io=N*2-1;io>=mid+1;io--){
					ovo[io]=ovo[io-1];
				}
				ovo[mid+1]=i;
				back++;
				int bef=ovo[mid+2];
				if(back==mid+1)bef=ovo[front];
				if(ch[ovo[mid+1]][bef]=='1'){
					mid++;
				}
				else{
					if(bef==ovo[front]){
						mid++;
					}
					else{
						mid+=2;
					}
				}
			}
		}
		if(ch[ovo[back]][ovo[front]]=='0'){
			front--;
			ovo[front]=ovo[back];
			back--;
		}
		for(int i=front;i<=back;i++)printf("%d ",ovo[i]);
		printf("\n");
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5788kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3 
4 1 2 3 

result:

ok 2 cases.

Test #2:

score: 0
Accepted
time: 0ms
memory: 5852kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

3 1 2 
1 3 2 
2 3 1 
1 2 3 

result:

ok 4 cases.

Test #3:

score: 0
Accepted
time: 2ms
memory: 5800kb

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:

4 1 2 3 
4 1 2 3 
1 3 4 2 
2 3 4 1 
2 1 4 3 
3 4 1 2 
1 2 3 4 
2 1 4 3 
1 3 4 2 
1 3 2 4 
4 1 2 3 

result:

ok 11 cases.

Test #4:

score: 0
Accepted
time: 3ms
memory: 5860kb

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:

5 1 2 3 4 
1 2 3 4 5 
5 1 2 3 4 
4 1 2 3 5 
4 1 2 3 5 
2 1 4 5 3 
2 3 4 5 1 
3 1 5 2 4 
1 5 4 2 3 
1 3 2 4 5 
1 2 3 4 5 
2 3 5 4 1 
2 3 4 5 1 
1 5 2 4 3 
2 4 5 3 1 
2 1 4 5 3 
1 5 2 3 4 
1 4 5 2 3 
1 2 5 4 3 
2 5 4 1 3 
3 1 2 5 4 
2 5 1 4 3 
2 4 5 1 3 
1 2 4 5 3 
1 3 2 5 4 
1 3 5 4 2 
4 1 2 3 5 
1 2...

result:

ok 34 cases.

Test #5:

score: 0
Accepted
time: 5ms
memory: 5928kb

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:

6 1 2 3 4 5 
6 1 2 3 4 5 
6 1 3 4 5 2 
3 1 2 5 6 4 
3 1 2 5 6 4 
2 1 4 5 6 3 
1 2 5 6 4 3 
3 1 2 5 6 4 
1 4 2 5 6 3 
2 1 6 5 4 3 
2 1 6 5 4 3 
1 6 5 4 3 2 
1 4 6 5 2 3 
5 6 1 2 3 4 
1 2 3 4 5 6 
1 2 3 4 5 6 
1 5 4 3 2 6 
1 6 5 2 3 4 
1 3 2 4 5 6 
3 4 5 6 1 2 
4 5 6 1 2 3 
3 4 6 5 1 2 
1 4 6 5 2 3 
1...

result:

ok 156 cases.

Test #6:

score: 0
Accepted
time: 2ms
memory: 5868kb

input:

7
0000010
0001011
0001010
0110100
0001001
1110001
0100110
7
0101001
1011000
0101100
1110010
0010010
0001100
1000000
7
0001111
0011001
0100100
1100101
1011000
1000000
1101000
7
0111111
1011101
1101001
1110010
1100010
1001101
1110010
7
0010111
0010001
1101010
0010000
1000011
1010100
1100100
7
0001010
...

output:

3 1 2 5 6 4 7 
1 5 7 6 4 3 2 
2 1 3 6 5 7 4 
4 7 6 5 1 2 3 
2 1 4 7 5 6 3 
2 1 5 6 7 4 3 
2 1 6 7 5 4 3 
7 1 3 4 5 2 6 
1 2 5 4 6 7 3 
1 2 5 4 6 3 7 
1 6 7 4 3 2 5 
1 7 3 6 4 5 2 
2 1 4 3 5 6 7 
7 1 2 3 4 5 6 
2 6 7 5 4 3 1 
3 4 5 6 7 1 2 
5 1 3 2 4 6 7 
2 6 7 4 3 1 5 
4 5 6 1 7 3 2 
1 3 2 4 5 6 7 
...

result:

ok 286 cases.

Test #7:

score: 0
Accepted
time: 4ms
memory: 5928kb

input:

5
01000
10100
01010
00100
00000
9
001101110
001010001
110100110
101010000
010100011
100000000
101000000
101010001
010010010
4
0000
0011
0101
0110
8
00100101
00101100
11000011
00001111
01010101
11011000
00110000
10111000
9
000000001
001101000
010000100
010000111
000000000
010000111
001101010
00010110...

output:

1 4 5 3 2 
2 6 5 7 4 9 8 1 3 
2 1 4 3 
2 1 4 3 6 7 8 5 
2 1 3 4 5 9 8 7 6 
1 3 2 4 
1 2 3 5 6 4 
1 4 5 3 6 2 
3 5 6 7 4 1 2 
1 7 6 5 3 2 4 
1 9 8 10 6 7 4 3 2 5 
8 1 2 5 6 4 7 3 10 9 
1 5 4 2 3 6 
1 5 6 2 7 8 4 3 
3 9 1 8 6 7 5 2 4 
2 1 3 
1 2 3 
1 3 2 4 5 6 
1 3 4 5 6 7 2 
1 3 2 
2 1 3 
2 3 5 4 1 
...

result:

ok 322 cases.

Test #8:

score: 0
Accepted
time: 2ms
memory: 5868kb

input:

10
0010001000
0010011001
1101101001
0010111000
0011000110
0101001100
1111010001
0000110011
0000100101
0110001110
10
0000000010
0000001001
0000001101
0000100000
0001010111
0000101011
0110010100
0010101000
1000110000
0110110000
10
0110010111
1011111110
1100101010
0100001101
0110001111
1100001010
01111...

output:

2 1 5 7 10 9 8 6 4 3 
4 1 2 8 9 10 3 7 6 5 
1 4 9 10 8 5 7 6 2 3 
1 2 3 7 6 8 5 9 10 4 
2 1 4 5 9 10 8 7 6 3 
1 3 2 4 9 8 10 7 6 5 
2 3 4 5 6 7 8 9 10 1 
1 3 4 2 7 10 9 8 6 5 
2 1 3 4 6 7 8 9 10 5 
1 3 4 6 5 8 9 10 7 2 
2 3 4 5 1 10 7 9 8 6 
5 1 2 3 9 10 4 8 7 6 
1 6 10 7 9 8 2 5 4 3 
1 4 5 6 7 9 10...

result:

ok 200 cases.

Test #9:

score: 0
Accepted
time: 4ms
memory: 5868kb

input:

10
0110101100
1010100111
1101100101
0010111010
1111001010
0001000000
1001100111
1110001001
0101101000
0110001100
10
0111110111
1001111100
1001100100
1110101111
1111001010
1100001000
0101110100
1111001010
1001100100
1001000000
10
0100000111
1011111001
0100001111
0100100110
0101011100
0100100110
01101...

output:

1 6 8 9 10 7 4 5 2 3 
5 10 9 8 7 6 2 4 3 1 
1 10 3 9 6 8 7 5 4 2 
3 4 5 1 7 10 9 8 6 2 
1 5 6 3 7 8 10 9 2 4 
1 6 9 10 8 7 4 3 2 5 
6 7 8 10 9 3 5 4 1 2 
1 7 6 10 8 9 5 3 4 2 
3 9 10 8 7 6 5 4 1 2 
5 2 3 4 1 8 10 9 7 6 
6 10 9 8 7 1 5 4 3 2 
3 4 5 6 7 8 9 10 1 2 
2 3 10 9 8 7 6 5 4 1 
4 1 2 3 6 7 10...

result:

ok 200 cases.

Test #10:

score: 0
Accepted
time: 2ms
memory: 5940kb

input:

20
00011111000111100010
00100111111000000010
01011011101000100111
10100010000100000010
10100100000010101101
11001001010010000111
11110000010000111001
11100100111000010101
01100001011101100010
01000111100111011001
01100001100111111111
10010000111001010000
10001100011001001000
10000000111110111010
101...

output:

19 20 3 18 17 16 7 15 14 13 11 12 10 9 8 2 6 5 1 4 
10 1 4 5 6 3 7 8 9 12 13 2 14 11 15 18 19 17 16 
2 3 6 11 10 12 22 7 21 15 20 14 19 18 17 16 13 9 8 4 5 1 
1 2 5 6 13 11 12 10 9 8 7 4 3 
3 1 2 5 6 7 4 10 11 14 13 15 16 24 25 23 27 30 28 29 26 22 18 21 20 19 17 12 9 8 
1 3 5 6 7 4 8 10 11 9 12 2 1...

result:

ok 72 cases.

Test #11:

score: 0
Accepted
time: 6ms
memory: 5964kb

input:

59
01110100011001000100111000110110010001011111001011011101100
10001011111001111100111111100010111011100101001100001000101
10000011101010011100111011000001101110001100001110110101001
10001100100110101001000000101101101110001110111001110001101
010101010101101111110011111000100101111111101001111100111...

output:

2 3 6 10 9 14 15 13 16 12 17 11 18 19 7 20 22 23 24 28 29 32 33 34 31 37 39 38 40 41 36 42 43 44 45 46 47 51 52 53 54 55 48 56 58 59 57 50 49 35 30 27 26 25 21 8 5 4 1 
1 3 7 6 8 9 10 5 11 14 15 13 16 26 27 29 30 31 32 33 28 34 35 25 36 38 42 43 44 41 45 39 46 48 49 47 50 54 56 57 62 63 58 61 60 59 ...

result:

ok 29 cases.

Test #12:

score: 0
Accepted
time: 3ms
memory: 8008kb

input:

160
0010110100011110110110110001100110111000000100001100110101001011100101011100011100111011011011010011010110101100000011111010110111001011001100010000101111001101
000011011110000111010100011011010001001101001100111010101101001011001101001001000001011010001101100111011110110101111010101100000101001...

output:

1 10 11 12 2 13 15 16 17 20 21 19 22 24 25 26 27 32 33 36 40 39 41 46 48 49 52 53 51 62 63 61 64 56 65 66 68 69 71 72 74 75 76 77 78 80 79 88 91 113 116 154 160 155 159 158 157 156 153 115 152 117 151 119 150 120 149 118 148 137 147 138 146 143 145 144 139 142 140 141 122 136 131 135 134 132 133 124...

result:

ok 14 cases.

Test #13:

score: 0
Accepted
time: 4ms
memory: 6680kb

input:

438
01000100111101110010100101010001000101100011101011001001011110011100000110001001100101100101110011110111001101001101100111110010011001000110100110101001001101110001110011101010100010110100001011110011001000000001111111011001001010011101110010110111011111100011111101101001101010101010110000000111...

output:

1 5 6 9 10 8 18 19 20 21 17 22 16 23 15 24 26 27 40 41 43 44 42 45 39 47 48 46 49 76 77 81 82 83 84 85 75 86 88 91 90 92 89 95 96 99 110 115 116 111 121 120 122 117 124 125 126 123 127 128 133 134 137 138 139 136 140 135 141 142 143 146 145 147 144 148 129 161 162 163 164 165 170 172 176 175 177 180...

result:

ok 7 cases.

Test #14:

score: 0
Accepted
time: 0ms
memory: 9572kb

input:

1227
0100010000101001111110111010100100001100101111001011101010010000100111110110000001101101000101010011000101100110010011010100010011111000101101011001010111010010101001100100011000100000101011011011110101010011011110111101110010100010101111010101011001100001000110011101101010010011110010011011100...

output:

1 3 4 7 8 9 6 10 12 13 19 20 23 24 22 27 29 30 32 35 49 50 51 52 53 54 55 56 57 36 58 61 60 62 59 63 48 64 66 65 67 47 77 78 79 90 91 92 89 96 99 98 102 101 123 127 129 130 131 132 128 133 135 136 134 137 139 140 141 142 143 156 157 158 159 162 163 166 167 168 170 175 180 189 192 193 191 194 196 195...

result:

ok 2 cases.

Test #15:

score: 0
Accepted
time: 4ms
memory: 8084kb

input:

1078
0111011100111011000000110100010011001100100101011100111000110001110111110010111010110111010110001010100111101001110111010010000001000100110000000010000010111010101000000110101011011011000001100000011111010001010001101111011110111110000110111111111111101100110100011001110110111011111001110010110...

output:

1 10 11 12 13 14 9 15 17 19 20 18 26 25 31 30 35 36 37 34 38 39 40 42 43 44 45 47 48 46 51 54 53 56 57 65 66 67 68 70 71 69 72 77 76 78 79 75 83 82 84 86 88 92 93 94 96 97 98 95 99 91 100 101 108 109 110 111 112 113 121 122 125 128 132 133 135 136 149 153 152 154 155 157 156 159 160 167 171 187 188 ...

result:

ok 2 cases.

Test #16:

score: 0
Accepted
time: 15ms
memory: 8748kb

input:

1310
0110101010101111001001001110010101000100000000011001001110111010011000110110010000001110111100110100110110110000011001000101100100000011011111011100010001101111001100100000011100111111101101001011000101000011100101111011100101011111000100101110011110001101110110100111101101011000000000101000101...

output:

1 4 2 5 10 11 17 16 19 22 21 25 26 23 27 28 44 49 50 51 52 53 48 57 58 56 59 54 60 61 62 63 55 64 45 65 67 71 72 70 74 75 78 80 81 82 83 86 85 90 101 102 103 100 104 91 105 111 112 116 121 133 134 135 141 140 142 139 143 144 147 146 149 152 153 151 154 156 157 161 182 183 189 190 193 192 194 196 195...

result:

ok 2 cases.

Test #17:

score: 0
Accepted
time: 16ms
memory: 8620kb

input:

1542
0000100001001001100011001101100001110111010111001110111110011011001000110010001111000000100011101001000100000001111001110100110101101111000011100010000100000111010001010110101110000001000001110100101111100001110010111000111001010111011100100100111011010101001100100101110110011000001011001000011...

output:

1 2 6 8 9 7 10 5 11 4 12 3 13 14 15 18 19 23 24 30 31 35 39 46 45 47 53 54 44 55 52 57 59 63 64 65 67 68 69 70 71 66 74 78 79 87 94 95 103 104 124 125 126 127 128 105 129 123 130 131 122 132 133 134 135 138 139 137 140 141 145 146 147 144 148 149 150 142 151 153 155 154 156 164 165 167 166 168 163 1...

result:

ok 2 cases.

Test #18:

score: 0
Accepted
time: 5ms
memory: 8420kb

input:

2000
0101010000001001011001110100110110001010001110110101101100010010011100000111001100000000110111011111100001110001111011101101110010100100001001110010001111011110011011010000100001011100000000110011000110010100101010110100001010101001111101011001110011010001100110000110101110000001000101001101010...

output:

1 3 5 6 9 8 10 13 12 19 22 25 28 27 29 26 30 33 34 42 41 43 47 55 58 57 59 56 64 67 66 68 65 69 70 71 63 72 60 73 62 78 84 88 89 87 90 86 91 85 95 96 99 101 104 107 108 109 110 112 113 114 119 124 125 126 127 128 156 157 158 159 155 170 169 171 172 174 195 196 198 199 204 212 213 211 214 223 224 228...

result:

ok 1 cases.

Test #19:

score: 0
Accepted
time: 31ms
memory: 9392kb

input:

2000
0100001100010101000111011110110000001010100001111010011110111010011101000001100111011101101100000100100011001100011101011110101011101000010000000001010110001100011111100011010110101010001100011100011100000111011011100010110010100001111101011001010111111101011100111011110001101000111100110101000...

output:

4 1 3 2 5 9 10 13 15 14 16 17 12 20 19 21 22 18 23 11 24 8 25 28 29 30 27 31 26 32 33 38 39 37 40 42 46 47 50 49 77 78 76 79 80 73 84 85 83 86 97 98 117 118 120 119 121 133 132 134 149 151 150 152 148 153 155 154 156 157 158 160 161 163 162 164 165 166 168 169 170 167 171 185 186 187 189 193 194 190...

result:

ok 1 cases.

Test #20:

score: 0
Accepted
time: 10ms
memory: 9472kb

input:

2000
0110101010100011101110010101000111001011110000101111001110111111100111000101010001110111000110110001010000010101101001011001111111011111111111011111000011100001111110000101100100000110100100100110110010000101101101100100001101100010011100000011110000100100011110111001101001101100110111011101011...

output:

2 3 8 15 16 10 17 14 19 20 18 21 22 24 27 28 32 31 33 34 41 42 46 50 49 54 53 55 52 56 60 68 69 70 71 88 89 86 90 87 91 92 93 94 96 97 95 98 106 105 109 110 112 114 115 119 120 117 121 123 126 127 125 128 129 132 133 134 142 143 145 148 147 156 157 155 160 161 159 162 164 165 166 163 167 170 174 175...

result:

ok 1 cases.

Test #21:

score: 0
Accepted
time: 27ms
memory: 9112kb

input:

2000
0110000110000000010000010011101111110001110101010000000001101110101010101001111001010100100101001100010100101000110001000101000101010011011000000100011110100001000010000111100110111010110001000100011100100011111001011011111011111001101101111011111011111010011100001111010001011101110000000001011...

output:

1 14 15 17 16 18 4 19 20 21 23 24 25 30 31 32 33 29 34 41 44 45 53 54 57 64 65 72 73 74 75 82 85 86 87 84 89 90 88 91 83 92 99 98 100 101 102 97 103 95 104 105 109 110 119 120 121 122 118 125 126 133 134 127 136 137 138 143 146 147 148 145 157 158 166 167 168 165 169 162 173 174 175 177 178 176 179 ...

result:

ok 1 cases.

Test #22:

score: 0
Accepted
time: 16ms
memory: 7792kb

input:

2000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

2000 1 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

result:

ok 1 cases.

Test #23:

score: 0
Accepted
time: 10ms
memory: 9584kb

input:

2000
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...

result:

ok 1 cases.