This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int maxi=0;
int m, n;
bool dans(int lig, int col) {
if (lig<0||col<0||lig>=m||col>=n) return false;
else return true;
}
int main() {
scanf("%d%d", &m,&n);
int grille[1000000][10000000];
for (int lig=0;lig<m;lig++) {
for (int col=0;col<n;col++) {
cin >> grille[lig][col];
}
}
int k; cin >> k ;
for (int i=0;i<k;i++) {
int r, c; cin >> r >> c;
int maxiCur = 0;
// premier cas
if (dans(r-1,c-1)&&dans(r-1,c+1)&&dans(r-1,c)) {
maxiCur = max(maxiCur, grille[r-1][c-1]+grille[r-1][c]+grille[r-1][c+1]+grille[r][c]);
}
if (dans(r-1,c+1)&&dans(r+1,c+1)&&dans(r,c+1)) {
maxiCur= max(maxiCur, grille[r-1][c+1]+grille[r][c+1]+grille[r+1][c+1]+grille[r][c]);
}
if (dans(r+1,c-1)&&dans(r+1,c+1)&&dans(r+1,c)) {
maxiCur = max(maxiCur, grille[r+1][c-1]+grille[r+1][c]+grille[r+1][c+1]+grille[r][c]);
}
if (dans(r-1,c-1)&&dans(r+1,c-1)&&dans(r,c-1)) {
maxiCur = max(maxiCur, grille[r-1][c-1]+grille[r][c-1]+grille[r+1][c-1]+grille[r][c]);
}
// 2
// 3
// 4
maxi += maxiCur;
}
printf("%ld\n", maxi);
}
Compilation message (stderr)
covering.cpp: In function 'int main()':
covering.cpp:42:13: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Wformat=]
42 | printf("%ld\n", maxi);
| ~~^ ~~~~
| | |
| | int
| long int
| %d
covering.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%d%d", &m,&n);
| ~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |