QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555886#9251. Graph ChangingANewZhiyangfanWA 4ms3956kbC++142.4kb2024-09-10 11:44:382024-09-10 11:44:39

Judging History

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

  • [2024-09-10 11:44:39]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3956kb
  • [2024-09-10 11:44:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;

typedef long long LL ;
const int N = 1e5+10 ;

int q ;
int t , n , K , x , y ;

int f[50][50] , g[50][50] ;
void pusher()
{
	memset( f , 0x3f , sizeof f ) ;
	for(int j = 1 ; j < n ; j ++ ) {
		f[j][j+1] = f[j+1][j] = 1 ;
		f[j][j] = 0 ;
	}
	f[n][n] = 0 ;
	bool fg = 0 ;
	for(int i = 0 ; i <= t ; i ++ ) {
		fg = 0 ;
		if( i == 0 ) memcpy( g , f , sizeof g ) ;
		else {
			memset( g , 0x3f , sizeof g ) ;
			for(int i = 1 ; i <= n ; i ++ ) {
				for(int j = 1 ; j <= n ; j ++ ) {
					if( f[i][j] >= K ) {
						g[i][j] = 1 ;
					}
				}
				g[i][i] = 0 ;
			}
		}
 		for(int k = 1 ; k <= n ; k ++ ) {
			for(int i = 1 ; i <= n ; i ++ ) {
				for(int j = 1 ; j <= n ; j ++ ) {
					g[i][j] = min( g[i][j] , g[i][k]+g[k][j] ) ;
				} 
			}
		}
		memcpy( f , g , sizeof f ) ;
		for(int i = 1 ; i <= n ; i ++ ) {
			for(int j = 1 ; j <= n ; j ++ ) {
				if( i == j ) continue ;
				if( f[i][j] >= 10 ) {
					f[i][j] = -1 ;
				}
				else fg = 1 ;
			}
		}
		if( !fg ) {
			printf("-1\n") ;
			return ;
		}
	}
	if( f[x][y] <= 10 ) printf("%d\n" , f[x][y] ) ;
	else printf("-1\n") ;
}

int main()
{
	scanf("%d" , &q ) ;
	while( q -- ) {
		scanf("%d%d%d%d%d" , &t , &n , &K , &x , &y ) ;
		if( K == 1 ) {
			if( t == 0 ) printf("%d\n" , abs(x-y) ) ;
			else printf("1\n") ;
			continue ;
		}
		if( K == 2 ) {
			if( n >= 5 ) {
				if( t&1 ) printf("%d\n" , abs(x-y)==1?2:1 ) ;
				else printf("%d\n" , abs(x-y) ) ; 
			}
			else if( n == 4 ) {
				if( t&1 ) {
					if( (x==2&&y==3)||(x==3&&y==2) ) printf("3\n") ;
					else if( abs(x-y) == 1 ) printf("2\n") ;
					else printf("1\n") ;
				}
				else printf("%d\n" , abs(x-y) ) ; 
			}
			else if( n == 3 ) {
				if( t >= 2 ) printf("-1\n") ;
				else if( t == 1 ) printf("%d\n" , ((x==1&&y==3)||(x==3&&y==1))?1:-1 ) ;
				else printf("%d\n" , abs(x-y) ) ;
			}
			else {
				printf("%d\n" , t?-1:1 ) ;
			}
			continue ;
		}
		if( n <= 40 ) {
			pusher() ;
			continue ;
		}
		if( K >= 3 ) {
			if( t == 0 ) printf("%d\n" , abs(x-y) ) ;
			else if( t == 1 ) {
				if( abs(x-y) >= K ) printf("1\n") ;
				else if( (abs(x-1)>=K&&abs(y-1)>=K)||(abs(n-x)>=K&&abs(n-y)>=K) ) printf("2\n") ;
				else if( (abs(x-1)>=K&&abs(n-y)>=K)||(abs(n-x)>=K&&abs(y-1)>=K ) ) printf("3\n") ;
				else printf("-1\n") ; 
			}
			else printf("-1\n") ;
			continue ;
		}
	}
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3764kb

input:

5
1 5 3 2 4
1 10 4 2 4
2 10 5 2 4
1 3 2 1 3
1 3 2 1 2

output:

3
2
-1
1
-1

result:

ok 5 lines

Test #2:

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

input:

30
1 2 1 1 2
1 2 2 1 2
1 2 3 1 2
1 2 4 1 2
1 2 5 1 2
1 2 6 1 2
2 2 1 1 2
2 2 2 1 2
2 2 3 1 2
2 2 4 1 2
2 2 5 1 2
2 2 6 1 2
3 2 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1
-1
-1
-1
-1
-1
2
2
2
2
-1
-1...

result:

ok 840 lines

Test #9:

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

input:

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

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
2
1
2
2
2
2
2
2
1
1
1
1
1
2
2
2
1
1
1
1
2
2
3
1
1
1
2
3
3
1
1
2
2
2
1
2
2
2
2
2
2
2
2
2
-1
1
1...

result:

ok 1080 lines

Test #10:

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

input:

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

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
2
1
2
2
2
2
2
2
1
1
1
1
1
1
2
2
2
1
1
1
...

result:

ok 1350 lines

Test #11:

score: -100
Wrong Answer
time: 4ms
memory: 3956kb

input:

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

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
1
2
2
2
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
...

result:

wrong answer 120th lines differ - expected: '1', found: '2'