QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665893#8632. 算式密码锁zhuluoan100 ✓15ms9376kbC++142.2kb2024-10-22 15:45:482024-10-22 15:46:03

Judging History

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

  • [2024-10-22 15:46:03]
  • 评测
  • 测评结果:100
  • 用时:15ms
  • 内存:9376kb
  • [2024-10-22 15:45:48]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std ;
# define ull unsigned long long
# define ll long long
# define db double
# define random( a , b ) ( rand( ) % ( ( b ) - ( a ) + 1 ) + ( a ) )
# define se second
# define fi first
# define pr pair < int , int >
# define pb push_back
# define ph push
# define ft front
# define vec vector
# define For( i , a , b ) for ( int i = a ; i <= b ; i ++ )
# define Rep( i , a , b ) for ( int i = a ; i >= b ; i -- )
# define mem( a , b ) memset ( a , b , sizeof ( a ) )
# define NO cout << "NO" << "\n" ;
# define YES cout << "YES" << "\n" ;
# define No cout << "No" << "\n" ;
# define Yes cout << "Yes" << "\n" ;
# define rt return
# define str string
const int N = 20 , M = 1e7 ;
int T , n , g [ N ] , f [ N ] , ans , Cnt , vis [ M ] ;
char s [ N ][ N ] ;
inline int check (  )
{
	double tot = 0 ;
	int a = s [ 0 ][ f [ 0 ] ] - '0' , b = s [ 1 ][ f [ 1 ] ] ;
	int c = s [ 2 ][ f [ 2 ] ] - '0' , d = s [ 3 ][ f [ 3 ] ];
	if ( b == '+' ) tot = a + c ;
	if ( b == '-' ) tot = a - c ;
	if ( b == '*' ) tot = a * c ;
	if ( b == '/' )
	{
		if ( c == 0 )
		{
			return 0 ;
		}
		tot = a * 1.0 / c ;
	}
	int sum = ( s [ 4 ][ f [ 4 ] ] - '0' ) * 10 + s [ 5 ][ f [ 5 ] ] - '0' ;
	if ( d == '>' ) return tot > sum ;
	if ( d == '=' ) return tot == sum ;
	if ( d == '<' ) return tot < sum ; 
}
inline void dfs ( int cnt , int r )
{
	if ( cnt > 5 )
	{
		if ( vis [ r ] == 1 )
		{
			return ;
		}
		int ans1 = 0 ;
		For ( i , 0 , n - 1 )
		{
			int R = 0 ;
			For ( j , 0 , 5 )
			{
				f [ j ] = ( g [ j ] + i ) % n ;
				R = R * 10 + f [ j ] ;
			}
			vis [ R ] = 1 ;
			if ( check ( ) == 1 ) ans1 ++ ;
		}
		ans = max ( ans1 , ans ) ;
        return ;
	}
	For ( i , 0 , n - 1 )
	{
		g [ cnt ] = i ;
		dfs ( cnt + 1 , r * 10 + i ) ;
	}
}
void solve ( )
{
    cin >> n ;
    For ( i , 0 , 5 )
    {
    	cin >> s [ i ] ;
	}
	dfs ( 0 , 0 )  ;
	cout << ans << "\n" ;
}
int main ( )
{
//	freopen ( "lock.in" , "r" , stdin ) ;
//	freopen ( "lock.out" , "w" , stdout ) ;
	ios :: sync_with_stdio ( false ) ;
    cin . tie ( 0 ) ;
    srand ( time ( 0 ) ) ;
//    cin >> T ;
//    while ( T -- )
	solve ( ) ;
	rt 0 ;
}

详细


Pretests


Final Tests

Test #1:

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

input:

1
7
+
9
=
1
6

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1
3
+
8
=
4
5

output:

0

result:

ok single line: '0'

Test #3:

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

input:

1
8
+
8
<
1
5

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1
5
+
6
>
1
0

output:

1

result:

ok single line: '1'

Test #5:

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

input:

1
2
*
8
=
1
6

output:

1

result:

ok single line: '1'

Test #6:

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

input:

1
8
/
3
=
0
2

output:

0

result:

ok single line: '0'

Test #7:

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

input:

1
9
/
6
>
0
1

output:

1

result:

ok single line: '1'

Test #8:

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

input:

1
7
-
7
>
7
4

output:

0

result:

ok single line: '0'

Test #9:

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

input:

1
5
+
2
<
0
9

output:

1

result:

ok single line: '1'

Test #10:

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

input:

2
32
++
47
==
10
06

output:

2

result:

ok single line: '2'

Test #11:

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

input:

2
15
++
41
==
70
61

output:

1

result:

ok single line: '1'

Test #12:

score: 5
Accepted
time: 14ms
memory: 7840kb

input:

10
5063152515
++++++++++
3643427729
==========
1729333612
7714289416

output:

1

result:

ok single line: '1'

Test #13:

score: 5
Accepted
time: 14ms
memory: 8932kb

input:

10
5699749655
++++++++++
4486705309
==========
0690847717
9735641858

output:

3

result:

ok single line: '3'

Test #14:

score: 5
Accepted
time: 15ms
memory: 9328kb

input:

10
1672370904
++++++++++
8835825976
><><=><<<<
7640932128
5621497720

output:

8

result:

ok single line: '8'

Test #15:

score: 5
Accepted
time: 15ms
memory: 9376kb

input:

10
1458060574
++++++++++
6380400163
=>>><>>=>=
7765073124
7628127469

output:

3

result:

ok single line: '3'

Test #16:

score: 5
Accepted
time: 15ms
memory: 9012kb

input:

10
2709586364
/---*/+/++
9992425165
==========
4129100709
2377293095

output:

4

result:

ok single line: '4'

Test #17:

score: 5
Accepted
time: 14ms
memory: 7852kb

input:

10
7209588823
*/*+*-++-*
6913916311
==========
5186517243
4256032489

output:

3

result:

ok single line: '3'

Test #18:

score: 5
Accepted
time: 5ms
memory: 7032kb

input:

8
74122886
-*/**+/*
44018012
>==<>>=<
04336845
12552226

output:

5

result:

ok single line: '5'

Test #19:

score: 5
Accepted
time: 4ms
memory: 8040kb

input:

9
362285771
---++*+//
894616931
<==<><<=<
770556473
084205441

output:

7

result:

ok single line: '7'

Test #20:

score: 5
Accepted
time: 15ms
memory: 7704kb

input:

10
4263385446
+-*-++++*/
8152614990
>>==<>===<
4536040292
8354005890

output:

6

result:

ok single line: '6'