Submission #227918

# Submission time Handle Problem Language Result Execution time Memory
227918 2020-04-29T08:55:34 Z Vimmer Strah (COCI18_strah) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 305
#define M ll(1e9 + 7)

using namespace std;

//using namespace __gnu_pbds;

typedef long double ld;

typedef long long ll;

typedef short int si;

//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, m, pr[N][N];

ll ans;

bool gd(int i, int j, int a, int b)
{
    int sm = pr[i + a - 1][j + b - 1];

    if (i != 0) sm -= pr[i - 1][j + b - 1];

    if (j != 0) sm -= pr[i + a - 1][j - 1];

    if (i != 0 && j != 0) sm += pr[i - 1][j - 1];

    return sm == 0;
}
int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;

    string s[n];

    for (int i = 0; i < n; i++) cin >> s[i];

    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
      {
          if (i != 0) pr[i][j] += pr[i - 1][j];

          if (j != 0) pr[i][j] += pr[i][j - 1];

          if (i != 0 && j != 0) pr[i][j] -= pr[i - 1][j - 1];

          if (s[i][j] == '#') pr[i][j]++;
      }

   for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        for (int a = 1; a <= n - i; a++)
        {
            int l = 1, r = m - j;

            while (l + 1 < r)
            {
                int md = (l + r) >> 1;

                if (gd(i, j, a, md)) l = md; else r = md - 1;
            }

            while (l > 0 && !gd(i, j, a, l)) l--;

            while (l < m - j && gd(i, j, a, l + 1)) l++;

            ll s = l, st = a;

            s = (s * (s + 1)) / 2;

            ans += s * st;
        }

    cout << ans << endl;
}
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 305
#define M ll(1e9 + 7)

using namespace std;

//using namespace __gnu_pbds;

typedef long double ld;

typedef long long ll;

typedef short int si;

//typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, m, pr[N][N];

ll ans;

bool gd(int i, int j, int a, int b)
{
    int sm = pr[i + a - 1][j + b - 1];

    if (i != 0) sm -= pr[i - 1][j + b - 1];

    if (j != 0) sm -= pr[i + a - 1][j - 1];

    if (i != 0 && j != 0) sm += pr[i - 1][j - 1];

    return sm == 0;
}
int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;

    string s[n];

    for (int i = 0; i < n; i++) cin >> s[i];

    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
      {
          if (i != 0) pr[i][j] += pr[i - 1][j];

          if (j != 0) pr[i][j] += pr[i][j - 1];

          if (i != 0 && j != 0) pr[i][j] -= pr[i - 1][j - 1];

          if (s[i][j] == '#') pr[i][j]++;
      }

   for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        for (int a = 1; a <= n - i; a++)
        {
            int l = 1, r = m - j;

            while (l + 1 < r)
            {
                int md = (l + r) >> 1;

                if (gd(i, j, a, md)) l = md; else r = md - 1;
            }

            while (l > 0 && !gd(i, j, a, l)) l--;

            while (l < m - j && gd(i, j, a, l + 1)) l++;

            ll s = l, st = a;

            s = (s * (s + 1)) / 2;

            ans += s * st;
        }

    cout << ans << endl;
}

Compilation message

strah.cpp: In function 'int main()':
strah.cpp:70:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (int i = 0; i < n; i++)
    ^~~
strah.cpp:94:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     cout << ans << endl;
     ^~~~
strah.cpp: At global scope:
strah.cpp:125:5: error: redefinition of 'int n'
 int n, m, pr[N][N];
     ^
strah.cpp:30:5: note: 'int n' previously declared here
 int n, m, pr[N][N];
     ^
strah.cpp:125:8: error: redefinition of 'int m'
 int n, m, pr[N][N];
        ^
strah.cpp:30:8: note: 'int m' previously declared here
 int n, m, pr[N][N];
        ^
strah.cpp:125:18: error: redefinition of 'int pr [305][305]'
 int n, m, pr[N][N];
                  ^
strah.cpp:30:11: note: 'int pr [305][305]' previously declared here
 int n, m, pr[N][N];
           ^~
strah.cpp:127:4: error: redefinition of 'll ans'
 ll ans;
    ^~~
strah.cpp:32:4: note: 'll ans' previously declared here
 ll ans;
    ^~~
strah.cpp: In function 'bool gd(int, int, int, int)':
strah.cpp:129:6: error: redefinition of 'bool gd(int, int, int, int)'
 bool gd(int i, int j, int a, int b)
      ^~
strah.cpp:34:6: note: 'bool gd(int, int, int, int)' previously defined here
 bool gd(int i, int j, int a, int b)
      ^~
strah.cpp: In function 'int main()':
strah.cpp:141:5: error: redefinition of 'int main()'
 int main()
     ^~~~
strah.cpp:46:5: note: 'int main()' previously defined here
 int main()
     ^~~~
strah.cpp:165:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (int i = 0; i < n; i++)
    ^~~
strah.cpp:189:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     cout << ans << endl;
     ^~~~