Submission #337618

# Submission time Handle Problem Language Result Execution time Memory
337618 2020-12-21T09:23:14 Z kutbilim_one UFO (IZhO14_ufo) C++14
0 / 100
137 ms 262148 KB
/** kutbilim.one **/
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(x) x.begin(),x.end()
#define int long long
#define endl '\n'
                               
ifstream in("test.txt"); 
#define cin in                   
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, m, r, k, p;
    cin >> n >> m >> r >> k >> p;
    
    vector< vector<int> > a(n+1, vector<int>(m+1));
    for(int i = 1; i <= n; i++)
	for(int j = 1; j <= m; j++) cin >> a[i][j];
 
    vector<int> maxi(n+1, -1), maxj(m+1, -1);
	while(k--){
		char side;
		int pos, h;
		cin >> side >> pos >> h;
 
		int shots = r;
		if(side == 'W' && (maxi[pos] == -1 || maxi[pos] >= h)){
			for(int j = 1; j <= m && shots > 0; j++){
				if(a[pos][j] >= h) a[pos][j]--, shots--;
				if(maxi[pos] == -1 || maxi[pos] < a[pos][j]) maxi[pos] = a[pos][j];
			}
		}else if(side == 'E' && (maxi[pos] == -1 || maxi[pos] >= h)){
		    for(int j = m; j >= 1 && shots > 0; j--){
				if(a[pos][j] >= h) a[pos][j]--, shots--;
				if(maxi[pos] == -1 || maxi[pos] < a[pos][j]) maxi[pos] = a[pos][j];
			}
		}else if(side == 'N' && (maxj[pos] == -1 || maxj[pos] >= h)){
		    for(int i = 1; i <= n && shots > 0; i++){
				if(a[i][pos] >= h) a[i][pos]--, shots--;
				if(maxj[pos] == -1 || maxj[pos] < a[i][pos]) maxj[pos] = a[i][pos];
			}	
		}else if(side == 'S' && (maxj[pos] == -1 || maxj[pos] >= h)){
		    for(int i = n; i >= 1 && shots > 0; i--){
				if(a[i][pos] >= h) a[i][pos]--, shots--;
				if(maxj[pos] == -1 || maxj[pos] < a[i][pos]) maxj[pos] = a[i][pos];
			}
		}
	}
 
	vector< vector<int> > sums(n+2, vector<int>(m+1));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
        	sums[i][j] += a[i][j] + sums[i][j-1];
        }
	}
	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++){
        	sums[j][i] += sums[j-1][i];
        }
	}
	                  
	int maxx = 0;
	for(int i = p; i <= n; i++){
		for(int j = p; j <= m; j++){
			maxx = max(maxx, sums[i][j]-sums[i][j-p]-sums[i-p][j]+sums[i-p][j-p]);	
		} 
	}
	    
    cout << maxx;
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 131 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 137 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 127 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 129 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 128 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 127 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 128 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 133 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 128 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 128 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 129 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 130 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 126 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 131 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 132 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 132 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 129 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 129 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 132 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 128 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)