답안 #496808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496808 2021-12-22T04:43:48 Z vinnipuh01 Maxcomp (info1cup18_maxcomp) C++17
0 / 100
98 ms 94408 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    freopen ( "sum.in", "r", stdin )
*/

set<int> dp[ 1001 ][ 1001 ][ 2 ];
int a[ 1001 ][ 1001 ];


main () {
	int n, m;
	cin >> n >> m;
	for ( int i = 0; i < n; i ++ ) {
		for ( int j = 0; j < m; j ++ ) {
			cin >> a[ i ][ j ];
		}
	}
	if ( n * m <= 20 ) {
		ans = 1;
		for ( int mask = 0; mask < ( 1 << ( n * m ) ); mask ++ ) {
			for ( int i = 0; i < n; i ++ ) {
				for ( int j = 0; j < m; j ++ ) {
					num = ( i ) * m + j;
					if ( mask & ( 1 << num ) ) {
						ans = 0;
						if ( i ) {
							if ( mask & ( 1 << ( num - m ) ) )
								ans = 1;
						}
						if ( j )
							if ( mask & ( 1 << ( num - 1 ) ) )
								ans = 1;
						if ( i < n - 1 )
							if ( mask & ( 1 << ( num + m ) ) )
								ans = 1;
						if ( j < m - 1 ) {
							if ( mask & ( 1 << ( num + 1 ) ) )
								ans = 1;
						}
					}
					if ( !ans )
						break;
				}
				if ( !ans )
					break;
			}
			if ( !ans )
				continue;
			for ( int i = 0; i < n; i ++ ) {
				for ( int j = 0; j < m; j ++ ) {
					num = i * m + j;
					if ( mask & ( 1 << num ) ) {
						mx = max( mx, a[ i ][ j ] );
						mn = min( mn, a[ i ][ j ] );
						sum ++;
					}
				}
			}
			pos = max( pos, mx - mn - sum );
			mx = 0;
			sum = 0;
			mn = oo;
		}
		cout << pos;
	}
	else {
		
	}
}


/*
4
3 3 4

4 ^ 6 ^ 8 ^ 5 ^ 6 ^ 7 = 14

2 3
2 4 3
5 7 5

*/

Compilation message

maxcomp.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 94404 KB Output is correct
2 Incorrect 98 ms 94408 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 94340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 94404 KB Output is correct
2 Incorrect 98 ms 94408 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 94404 KB Output is correct
2 Incorrect 98 ms 94408 KB Output isn't correct
3 Halted 0 ms 0 KB -