답안 #922360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922360 2024-02-05T12:36:32 Z thunopro 최솟값 배열 (IZhO11_hyper) C++14
0 / 100
254 ms 53168 KB
#include<bits/stdc++.h>
using namespace std ; 
#define maxn 200009 
#define ll long long 
#define fi first 
#define se second 
#define pb push_back 
#define left id<<1
#define right id<<1|1 
#define re exit(0); 

const int mod = 1e9+7; 
const int INF = 1e9; 

typedef vector<int> vi; 
typedef pair<int,int> pii;
typedef vector<pii> vii;  
typedef vector<ll> vl;

void add ( int &a , int b ) 
{
	a += b ; 
	if ( a > mod ) a -= mod ; 
	if ( a < 0 ) a += mod ; 
}

template <typename T> void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template <typename T> void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }

int _pow ( int a , int n ) 
{
	if ( n == 0 ) return 1 ;
	int res = _pow (a,n/2) ; 
	if ( n % 2 ) return 1ll*res*res%mod*a%mod ; 
	else return 1ll*res*res%mod ; 
}

void rf () 
{
	freopen ("bai1.inp","r",stdin) ;
}
const int nm = 35 ; 
int n , m ; 
int a [nm][nm][nm][nm] ;
int f1 [nm][nm][nm][nm] , f2 [nm][nm][nm][nm] , f3 [nm][nm][nm][nm] , f4 [nm][nm][nm][nm] ;  

deque <int> dq ; 

int main () 
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
//	rf () ; 
	cin >> n >> m ; 
	
	for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j ++ ) for ( int k = 1 ; k <= n ; k ++ ) for ( int l = 1 ; l <= n ; l ++ ) cin >> a [i][j][k][l] ; 
	for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j ++ ) for ( int k = 1 ; k <= n ; k ++ )
	{
		dq.clear() ; 
		for ( int l = 1 ; l <= n ; l ++ ) 
		{
			if ( !dq.empty() && dq.front() + m <= l ) dq.pop_front(); 
			while ( !dq.empty() && a[i][j][k][l] <= a[i][j][k][dq.back()]) dq.pop_back(); 
			dq.pb(l); 
			if ( l >= m ) f1 [i][j][k][l] = a [i][j][k][dq.front()] ; 
		}
	}
	
	for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j ++ ) for ( int l = m ; l <= n ; l ++ )
	{
		dq.clear() ; 
		for ( int k = 1 ; k <= n ; k ++ ) 
		{
			if ( !dq.empty() && dq.front() + m <= k ) dq.pop_front(); 
			while ( !dq.empty() && f1[i][j][k][l] <= f1[i][j][dq.back()][l]) dq.pop_back(); 
			dq.pb(k); 
			if ( k >= m ) f2 [i][j][k][l] = f1 [i][j][dq.front()][l] ; 
		}
	}
	
	for ( int i = 1 ; i <= n ; i ++ ) for ( int k = m ; k <= n ; k ++ ) for ( int l = m ; l <= n ; l ++ )
	{
		dq.clear() ; 
		for ( int j = 1 ; j <= n ; j ++ ) 
		{
			if ( !dq.empty() && dq.front() + m <= j ) dq.pop_front(); 
			while ( !dq.empty() && f2[i][j][k][l] <= f2[i][dq.back()][k][l]) dq.pop_back(); 
			dq.pb(j); 
			if ( j >= m ) f3 [i][j][k][l] = f2 [i][dq.front()][k][l] ; 
		}
	}
	
	for ( int j = m ; j <= n ; j ++ ) for ( int k = m ; k <= n ; k ++ ) for ( int l = m ; l <= n ; l ++ )
	{
		dq.clear() ; 
		for ( int i = 1 ; i <= n ; i ++ ) 
		{
			if ( !dq.empty() && dq.front() + m <= i ) dq.pop_front(); 
			while ( !dq.empty() && f3[i][j][k][l] <= f3[dq.back()][j][k][l]) dq.pop_back(); 
			dq.pb(i); 
			if ( i >= m ) f4 [i][j][k][l] = f3[dq.front()][j][k][l] ; 
		}
	}
	for ( int i = m ; i <= n ; i ++ ) for ( int j = m ; j <= n ; j ++ ) for ( int k = m ; k <= n ; k ++ ) for ( int l = m ; l <= n ; l ++ ) cout << f4 [i][j][k][l] << " " ; 

}

Compilation message

hyper.cpp: In function 'void rf()':
hyper.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8540 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 5 ms 18920 KB Output is correct
4 Correct 4 ms 19036 KB Output is correct
5 Correct 5 ms 19032 KB Output is correct
6 Correct 11 ms 23524 KB Output is correct
7 Correct 12 ms 23388 KB Output is correct
8 Correct 21 ms 28764 KB Output is correct
9 Correct 33 ms 32368 KB Output is correct
10 Correct 21 ms 28732 KB Output is correct
11 Correct 56 ms 33872 KB Output is correct
12 Correct 103 ms 36408 KB Output is correct
13 Correct 81 ms 33236 KB Output is correct
14 Correct 142 ms 43088 KB Output is correct
15 Correct 254 ms 53168 KB Output is correct
16 Correct 121 ms 37340 KB Output is correct
17 Correct 153 ms 41172 KB Output is correct
18 Runtime error 127 ms 28932 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -