답안 #227948

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227948 2020-04-29T10:18:44 Z Vimmer Strah (COCI18_strah) C++14
0 / 110
718 ms 20472 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 2005
#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_equal <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 opr(int i, int j, int y)
{
    int l = 1, r = n - i;

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

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

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

    while (l < n - i && gd(i, j, l + 1, y)) l++;

    return l;
}
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 x = 0; x < n; x++)
        {
            vector <int> g; g.clear();

            for (int j = 0; j < m; j++)
            {
                if (s[x][j] == '#')
                {
                    sort(g.begin(), g.end());

                    for (int i = 0; i < sz(g); i++)
                    {
                        ll kol = sz(g) - i;

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

                        ll s = g[i]; s = (s * (s + 1)) / 2;

                        s *= kol;

                        ans += s;
                    }

                    g.clear();

                    continue;
                }

                int val = opr(x, j, 1);

                g.pb(val);
            }

            sort(g.begin(), g.end());

            for (int i = 0; i < sz(g); i++)
            {
                ll kol = sz(g) - i;

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

                ll s = g[i]; s = (s * (s + 1)) / 2;

                s *= kol;

                ans += s;
            }
        }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 2048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2048 KB Output is correct
2 Incorrect 16 ms 1920 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 8064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 203 ms 13556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 236 ms 8824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 9088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 718 ms 20472 KB Output isn't correct
2 Halted 0 ms 0 KB -