UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200555#2848. 小明的多米诺yizhiming1001ms1296kbC++859b2024-01-06 07:43:342024-01-06 12:00:47

answer

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#define int long long
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int N = 1e4+5;
int n;
int f[N][2][2];
signed main(){
	n = read();
	f[0][1][0] = f[0][1][1] = f[0][0][1] = 1e9;
	for(int i=1;i<=n;i++){
		int x,y;
		x = read()&1;y = read()&1;
		for(int j=0;j<=1;j++){
			for(int k=0;k<=1;k++){
				f[i][j][k] = f[i-1][j^x][k^y];
			}
		}
		swap(x,y);
		for(int j=0;j<=1;j++){
			for(int k=0;k<=1;k++){
				f[i][j][k] = min(f[i][j][k],f[i-1][j^x][k^y]+1);
			}
		}
	}
	if(f[n][0][0]>n){
		cout<<-1<<"\n";
		return 0;
	}
	cout<<f[n][0][0]<<"\n";
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

5
5 4
5 4
1 5
5 5
3 3

output:

1

result:

ok single line: '1'

Test #2:

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

input:

20
1 3
5 2
5 2
2 6
2 4
1 1
1 3
1 4
2 6
4 2
5 6
2 2
6 2
4 3
2 1
6 2
6 5
4 5
2 4
1 4

output:

-1

result:

ok single line: '-1'

Test #3:

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

input:

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

output:

-1

result:

ok single line: '-1'

Test #4:

score: 10
Accepted
time: 1ms
memory: 1160kb

input:

1
2 4

output:

0

result:

ok single line: '0'

Test #5:

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

input:

5
1 2
6 6
1 1
3 3
6 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2041
189527 341486
989388 490740
305174 711489
998492 971844
424442 832954
293154 906619
738735 4393...

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

3979
570645 799923
575548 225560
50785 677255
477674 515334
686797 369269
485765 185627
848520 36065...

output:

1

result:

ok single line: '1'

Test #8:

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

input:

4031
765434 704266
619465 472848
817491 309190
584154 137933
712959 888161
761709 256164
891988 6307...

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4083
95924 610408
662383 520138
585197 939125
691434 558533
539922 40952
37652 128501
735457 100886
...

output:

-1

result:

ok single line: '-1'

Test #10:

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

input:

4139
67899 398310
433171 883357
514946 423905
842270 593696
992632 761387
130816 229534
981617 89827...

output:

-1

result:

ok single line: '-1'