답안 #235763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235763 2020-05-29T16:07:44 Z Kalam Raspad (COI17_raspad) C++11
100 / 100
407 ms 197880 KB
// KALAM
# include<bits/stdc++.h>

using namespace std;

const int N = 100000 + 77 , NN = 0 + 77;
int n , m , Mnx , Mxx;
char S[N][NN];
bool M[N][NN];
long long A;
bool bad;
void dfs(int x , int y) {
   Mxx = max(Mxx , x);
   Mnx = min(Mnx , x);
   if(y == 1 || y == m)
      bad = 1;
   M[x][y] = 1;
   for(int i = -1;i <= 1;++ i)
      for(int j = -1;j <= 1;++ j) {
         int nx = x + i , ny = y + j;
         if(! M[nx][ny] && nx >= 1 && nx <= n && ny >= 1 && ny <= m && S[nx][ny] == '0')
            dfs(nx , ny);
      }
}
int main() {
   scanf("%d %d" , & n , & m);
   for(int i = 1;i <= n;++ i)
      scanf("%s" , S[i] + 1);
   for(int i = 1;i <= n;++ i)
      for(int j = 1;j <= m;++ j)
         A += 1ll * (S[i][j] - '0') * i * (n - i + 1);
   for(int i = 1;i <= n;++ i)
      for(int j = 1;j < m;++ j)
         if(S[i][j] == S[i][j + 1] && S[i][j] == '1')
            A -= 1ll * i * (n - i + 1);
   for(int i = 1;i < n;++ i)
      for(int j = 1;j <= m;++ j)
         if(S[i][j] == S[i + 1][j] && S[i][j] == '1')
            A -= 1ll * i * (n - i);

   for(int i = 1;i <= n;++ i)
      for(int j = 1;j <= m;++ j)
         if(! M[i][j] && S[i][j] == '0') {
            Mnx = Mxx = i;
            bad = 0;
            dfs(i , j);
            if(! bad)
               A += 1ll * (Mnx - 1) * (n - Mxx);
         }
   for(int i = 1;i < n;++ i)
      for(int j = 1;j < m;++ j)
         if(S[i][j] == S[i + 1][j] && S[i][j + 1] == S[i][j] && S[i + 1][j + 1] == S[i][j] && S[i][j] == '1')
            A += 1ll * i * (n - i);

   printf("%lld\n" , A);
   return 0;
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:26:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d" , & n , & m);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~
raspad.cpp:28:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%s" , S[i] + 1);
       ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 9 ms 2816 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 8 ms 1536 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4864 KB Output is correct
2 Correct 147 ms 56696 KB Output is correct
3 Correct 99 ms 17016 KB Output is correct
4 Correct 86 ms 64632 KB Output is correct
5 Correct 37 ms 5752 KB Output is correct
6 Correct 112 ms 17016 KB Output is correct
7 Correct 64 ms 16888 KB Output is correct
8 Correct 71 ms 13688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 9 ms 2816 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 8 ms 1536 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 20 ms 4864 KB Output is correct
15 Correct 147 ms 56696 KB Output is correct
16 Correct 99 ms 17016 KB Output is correct
17 Correct 86 ms 64632 KB Output is correct
18 Correct 37 ms 5752 KB Output is correct
19 Correct 112 ms 17016 KB Output is correct
20 Correct 64 ms 16888 KB Output is correct
21 Correct 71 ms 13688 KB Output is correct
22 Correct 277 ms 111072 KB Output is correct
23 Correct 270 ms 20448 KB Output is correct
24 Correct 212 ms 20312 KB Output is correct
25 Correct 399 ms 197880 KB Output is correct
26 Correct 182 ms 28152 KB Output is correct
27 Correct 255 ms 22008 KB Output is correct
28 Correct 233 ms 19448 KB Output is correct
29 Correct 407 ms 145584 KB Output is correct
30 Correct 184 ms 28280 KB Output is correct
31 Correct 206 ms 36088 KB Output is correct
32 Correct 163 ms 20472 KB Output is correct
33 Correct 185 ms 18424 KB Output is correct
34 Correct 239 ms 19192 KB Output is correct