Submission #713743

# Submission time Handle Problem Language Result Execution time Memory
713743 2023-03-23T02:02:03 Z ALTAKEXE Bob (COCI14_bob) C++14
120 / 120
126 ms 17888 KB
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
using namespace std;
int n, m, k;
int a[1005][1005];
int s[1005][1005];
struct t{
  int cnt;
  int v, h;
  long long  ms;
  t (int _cnt = 0, int _v = 0, int _h = 0, long long  _ms = 0){
    cnt = _cnt;
    v = _v; h = _h;
    ms = _ms;
  }
};
int main (){
  long long ans=0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      scanf("%d", &a[i][j]);
  for (int i = 0; i < n; ++i){
    stack <t> S;
    S.push(t(0, -1, 0, 0));
    for (int j = 0; j < m; ++j){
      s[i][j] = 1;
      if (i > 0 && a[i-1][j] == a[i][j]) s[i][j] += s[i-1][j];
      int sum = 1;
      while (S.top().v == a[i][j] && S.top().h >= s[i][j]){
	sum += S.top().cnt;
	S.pop();
      }
      long long  my_s = sum * (long long )s[i][j];
      if (S.top().v == a[i][j]) my_s += S.top().ms;
      ans += my_s;
      S.push(t(sum, a[i][j], s[i][j], my_s));
    }
  }
  printf("%lld", ans);
  return 0;
}

Compilation message

bob.cpp: In function 'int main()':
bob.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
bob.cpp:24:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |       scanf("%d", &a[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 4704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 14728 KB Output is correct
2 Correct 73 ms 10060 KB Output is correct
3 Correct 72 ms 10012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 17888 KB Output is correct
2 Correct 87 ms 10060 KB Output is correct
3 Correct 71 ms 10084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 17696 KB Output is correct
2 Correct 74 ms 9976 KB Output is correct
3 Correct 72 ms 10056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 17820 KB Output is correct
2 Correct 73 ms 9984 KB Output is correct
3 Correct 76 ms 10068 KB Output is correct