Submission #768130

#TimeUsernameProblemLanguageResultExecution timeMemory
768130Username4132Dijamant (COCI22_dijamant)C++14
70 / 70
259 ms86204 KiB
#include<iostream>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)

const int MAXN = 2010;
int n, m, ans, sum[2*MAXN][2*MAXN], pr[MAXN][MAXN];
bool arr[MAXN][MAXN];

inline int su(int x1, int y1, int x2, int y2){
    return sum[x1][y1]+sum[x2][y2]-sum[x1][y2]-sum[x2][y1];
}

bool test_diamond(int cx, int cy, int sz){
    if(sz<=0 || cx<sz || cy<sz || cx>=n-sz || cy>=m-sz) return false;
    int x=cx+cy+1, y=cx-cy+m;
    int s1 = su(x-sz-1, y-sz-1, x+sz, y+sz);
    int s2 = su(x-sz, y-sz, x+sz-1, y+sz-1);
    return s1==(sz<<2) && s2==0;
}

int main(){
    scanf("%d %d", &n, &m);
    forn(i, n) forn(j, m){
        char ch; scanf(" %c", &ch);
        sum[i+j+1][i-j+m] = arr[i][j] = (ch=='#');
    }
    forn(i, n+m) forn(j, n+m) sum[i+1][j+1]+=sum[i+1][j]+sum[i][j+1]-sum[i][j];
    forn(i, n){
        int lst = -1;
        forn(j, m){
            if(arr[i][j]) lst=j;
            pr[i][j]=lst;
        }
    }
    forn(i, n) forn(j, m) ans+=test_diamond(i, j, j - pr[i][j]);
    printf("%d\n", ans);
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:24:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         char ch; scanf(" %c", &ch);
      |                  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...