Submission #639156

# Submission time Handle Problem Language Result Execution time Memory
639156 2022-09-08T18:27:39 Z CaoHuuKhuongDuy Bob (COCI14_bob) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
typedef pair <int,int> ii;
const int N = 1e3 + 9;
const int oo = 1e10;
int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
void solve(int a[],int h[],bool kt)
{
    stack <int> s;
    h[0] = -oo;
    s.push(0);
    for (int i = 1;i <= m;i++)
      {
        while (h[i] < h[s.top()] && a[i] == a[s.top()]) s.pop();
        l[i] = s.top() + 1;
        s.push(i);
      }
    while (s.size()) s.pop();
    s.push(m + 1);
    h[m + 1] = -oo;
    for (int i = m;i >= 1;i--)
      {
        while (h[i] <= h[s.top()] && a[i] == a[s.top()]) s.pop();
        r[i] = s.top() - 1;
        s.push(i);
      }
    int lim_r;
    int tmp = res;
    for (int i = 1;i <= m;i++)
      {
        // if (kt) tmp = res;
        tmp = res;
        res += (i - l[i] + 1) * (r[i] - i + 1);
        if (a[r[i] + 1] != a[i] || r[i] == m) lim_r = 1;
        else lim_r = h[r[i] + 1] + 1;
        res += (h[i] - lim_r) * (r[i] - i + 1) + (lim_r - 1) * (r[i] - i + 1);
        // if (kt) cout<<i<<" "<<l[i]<<" "<<r[i]<<" "<<lim_r<<" "<<res - tmp<<endl;
      }  
    // cout<<res-tmp<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // freopen("test.inp","r",stdin);
    cin>>n>>m;
    for (int i = 1;i <= n;i++)
      for (int j = 1;j <= m;j++)
        cin>>a[i][j];
    for (int i = 1;i <= n;i++)
      for (int j = 1;j <= m;j++)
        if (a[i][j] != a[i-1][j]) high[i][j] = 1;
        else high[i][j] = high[i-1][j] + 1;
    for (int i = 1;i <= n;i++)
      solve(a[i],high[i],(i == 3));
    cout<<res;
    return 0;
}#include <bits/stdc++.h>
using namespace std;
#define int long long 
typedef pair <int,int> ii;
const int N = 1e3 + 9;
const int oo = 1e10;
int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
void solve(int a[],int h[],bool kt)
{
    stack <int> s;
    h[0] = -oo;
    s.push(0);
    for (int i = 1;i <= m;i++)
      {
        while (h[i] < h[s.top()] && a[i] == a[s.top()]) s.pop();
        l[i] = s.top() + 1;
        s.push(i);
      }
    while (s.size()) s.pop();
    s.push(m + 1);
    h[m + 1] = -oo;
    for (int i = m;i >= 1;i--)
      {
        while (h[i] <= h[s.top()] && a[i] == a[s.top()]) s.pop();
        r[i] = s.top() - 1;
        s.push(i);
      }
    int lim_r;
    int tmp = res;
    for (int i = 1;i <= m;i++)
      {
        // if (kt) tmp = res;
        tmp = res;
        res += (i - l[i] + 1) * (r[i] - i + 1);
        if (a[r[i] + 1] != a[i] || r[i] == m) lim_r = 1;
        else lim_r = h[r[i] + 1] + 1;
        res += (h[i] - lim_r) * (r[i] - i + 1) + (lim_r - 1) * (r[i] - i + 1);
        // if (kt) cout<<i<<" "<<l[i]<<" "<<r[i]<<" "<<lim_r<<" "<<res - tmp<<endl;
      }  
    // cout<<res-tmp<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // freopen("test.inp","r",stdin);
    cin>>n>>m;
    for (int i = 1;i <= n;i++)
      for (int j = 1;j <= m;j++)
        cin>>a[i][j];
    for (int i = 1;i <= n;i++)
      for (int j = 1;j <= m;j++)
        if (a[i][j] != a[i-1][j]) high[i][j] = 1;
        else high[i][j] = high[i-1][j] + 1;
    for (int i = 1;i <= n;i++)
      solve(a[i],high[i],(i == 3));
    cout<<res;
    return 0;
}

Compilation message

bob.cpp:59:2: error: stray '#' in program
   59 | }#include <bits/stdc++.h>
      |  ^
bob.cpp:59:3: error: 'include' does not name a type
   59 | }#include <bits/stdc++.h>
      |   ^~~~~~~
bob.cpp:63:11: error: redefinition of 'const long long int N'
   63 | const int N = 1e3 + 9;
      |           ^
bob.cpp:5:11: note: 'const long long int N' previously defined here
    5 | const int N = 1e3 + 9;
      |           ^
bob.cpp:64:11: error: redefinition of 'const long long int oo'
   64 | const int oo = 1e10;
      |           ^~
bob.cpp:6:11: note: 'const long long int oo' previously defined here
    6 | const int oo = 1e10;
      |           ^~
bob.cpp:65:5: error: redefinition of 'long long int n'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |     ^
bob.cpp:7:5: note: 'long long int n' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |     ^
bob.cpp:65:7: error: redefinition of 'long long int m'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |       ^
bob.cpp:7:7: note: 'long long int m' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |       ^
bob.cpp:65:9: error: redefinition of 'long long int a [1009][1009]'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |         ^
bob.cpp:7:9: note: 'long long int a [1009][1009]' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |         ^
bob.cpp:65:17: error: redefinition of 'long long int high [1009][1009]'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                 ^~~~
bob.cpp:7:17: note: 'long long int high [1009][1009]' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                 ^~~~
bob.cpp:65:28: error: redefinition of 'long long int l [1009]'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                            ^
bob.cpp:7:28: note: 'long long int l [1009]' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                            ^
bob.cpp:65:33: error: redefinition of 'long long int r [1009]'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                                 ^
bob.cpp:7:33: note: 'long long int r [1009]' previously declared here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                                 ^
bob.cpp:65:38: error: redefinition of 'long long int res'
   65 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                                      ^~~
bob.cpp:7:38: note: 'long long int res' previously defined here
    7 | int n,m,a[N][N],high[N][N],l[N],r[N],res = 0;
      |                                      ^~~
bob.cpp:66:6: error: redefinition of 'void solve(long long int*, long long int*, bool)'
   66 | void solve(int a[],int h[],bool kt)
      |      ^~~~~
bob.cpp:8:6: note: 'void solve(long long int*, long long int*, bool)' previously defined here
    8 | void solve(int a[],int h[],bool kt)
      |      ^~~~~
bob.cpp:100:8: error: redefinition of 'int main()'
  100 | signed main()
      |        ^~~~
bob.cpp:42:8: note: 'int main()' previously defined here
   42 | signed main()
      |        ^~~~