답안 #1090704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090704 2024-09-18T15:37:03 Z Kuzeuy54_ Zemljište (COCI22_zemljiste) C++17
0 / 70
4 ms 4444 KB
#include <bits/stdc++.h>
using namespace std;
#define inf 1e18
#define int long long
const int mod=1e9+7;
const int MAXN=505;
vector<vector<int>>dp(MAXN,vector<int>(MAXN,0));
vector<vector<int>>mat(MAXN,vector<int>(MAXN,0));
int omg(int x1,int y1,int x2,int y2){
	return dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1];
}
int32_t main(){
    int x,y,a,b,ans=inf,temp;
	cin>>x>>y>>a>>b;
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++)
			cin>>mat[i][j];
	for(int i=1;i<=x;i++)
		for(int j=1;j<=y;j++)
			dp[i][j]=mat[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
	for(int j=1;j<=y;j++)
		for(int i=1;i<=y;i++){
			int l=1,r=1;
			while(r<=y){
				int aq=omg(j,l,i,r);
				ans=min(abs(a-aq)+abs(b-aq),ans);
				if(aq>b){
					l++;
					if(l>r)
						r++;
				}
				else if(aq>=a){
					cout<<b-a;
					return 0;
				}
				else 
					r++;
			}
		}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 3 ms 4444 KB Output is correct
3 Correct 3 ms 4348 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4400 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 3 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 3 ms 4444 KB Output is correct
3 Correct 3 ms 4348 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4400 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 3 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4440 KB Output is correct
2 Correct 3 ms 4444 KB Output is correct
3 Correct 3 ms 4348 KB Output is correct
4 Correct 3 ms 4444 KB Output is correct
5 Correct 3 ms 4444 KB Output is correct
6 Correct 3 ms 4400 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Incorrect 3 ms 4440 KB Output isn't correct
9 Halted 0 ms 0 KB -