Submission #200553

# Submission time Handle Problem Language Result Execution time Memory
200553 2020-02-07T08:03:57 Z Kalam Bob (COCI14_bob) C++11
0 / 120
1000 ms 888 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] , b[N] , c[N];
int cur , f[N] , L[N] , R[N];
long long A;
inline void Calc() {
   c[0] = 0;
   c[cur + 1] = 0;
   for(int i = 1;i <= cur;++ i) {
      L[i] = i - 1;
      while(c[L[i]] >= c[i])
         L[i] = L[L[i]];
   }
   for(int i = cur;i > 0;-- i) {
      R[i] = i + 1;
      while(c[R[i]] > c[i])
         R[i] = R[R[i]];
      A += 1ll * (i - L[i]) * (R[i] - i) * c[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) , b[j] = a[i][j] , c[j] = i - up[i][j];
      int pv = 1;
      f[++ cur] = c[1];
      for(int j = 2;j <= m;++ j) {
         if(b[j] != b[j - 1])
            Calc();
         f[++ cur] = c[j];
      }
      Calc();
   }
   printf("%lld\n" , A);
	return 0;
}

Compilation message

bob.cpp: In function 'int main()':
bob.cpp:33:11: warning: unused variable 'pv' [-Wunused-variable]
       int pv = 1;
           ^~
bob.cpp:29: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:32:112: 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) , b[j] = a[i][j] , c[j] = i - up[i][j];
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1100 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1049 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 632 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -