Submission #200554

# Submission time Handle Problem Language Result Execution time Memory
200554 2020-02-07T08:13:59 Z Kalam Bob (COCI14_bob) C++11
120 / 120
207 ms 18424 KB
// KALAM
# include<bits/stdc++.h>

# define debug(x) cerr << #x << " = " << x << endl

using namespace std;

const int N = 1000 + 77;
int n , m , a[N][N] , up[N][N] , c[N];
int cur , f[N] , L[N] , R[N];
long long A;
inline void Calc() {
   f[0] = f[cur + 1] = 0;
   for(int i = 1;i <= cur;++ i) {
      L[i] = i - 1;
      while(f[L[i]] >= f[i])
         L[i] = L[L[i]];
   }
   for(int i = cur;i > 0;-- i) {
      R[i] = i + 1;
      while(f[R[i]] > f[i])
         R[i] = R[R[i]];
      A += 1ll * (i - L[i]) * (R[i] - i) * f[i];
   }
   cur = 0;
}
int main() {
   scanf("%d %d" , & n , & m);
   for(int i = 1;i <= n;++ i) {
      for(int j = 1;j <= m;++ j)
         scanf("%d" , & a[i][j]) , up[i][j] = (a[i][j] == a[i - 1][j] ? up[i - 1][j] : i - 1) , c[j] = i - up[i][j];
      f[++ cur] = c[1];
      for(int j = 2;j <= m;++ j) {
         if(a[i][j] != a[i][j - 1])
            Calc();
         f[++ cur] = c[j];
      }
      Calc();
   }
   printf("%lld\n" , A);
	return 0;
}

Compilation message

bob.cpp: In function 'int main()':
bob.cpp:28:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d" , & n , & m);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~
bob.cpp:31:95: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
          scanf("%d" , & a[i][j]) , up[i][j] = (a[i][j] == a[i - 1][j] ? up[i - 1][j] : i - 1) , c[j] = i - up[i][j];
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 15096 KB Output is correct
2 Correct 114 ms 10744 KB Output is correct
3 Correct 115 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 18296 KB Output is correct
2 Correct 129 ms 10744 KB Output is correct
3 Correct 113 ms 10696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 18296 KB Output is correct
2 Correct 111 ms 10744 KB Output is correct
3 Correct 115 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 18424 KB Output is correct
2 Correct 134 ms 10848 KB Output is correct
3 Correct 120 ms 10672 KB Output is correct