Submission #227914

# Submission time Handle Problem Language Result Execution time Memory
227914 2020-04-29T08:46:58 Z Vimmer Strah (COCI18_strah) C++14
44 / 110
1000 ms 9984 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 pr[N][N], t[N * 4][N * 4], n, m, psh[N * 4][N * 4];
//
//vector <pair <int, int> > pshr[N * 4];
//
//void Push(int V, int v, int tl, int tr, int l, int r)
//{
//    if (psh[V][v] == 0) return;
//
//    t[V][v] += (r - l + 1) * psh[V][v];
//
//    if (tl != tr)
//    {
//        psh[V][v + v] += psh[V][v];
//
//        psh[V][v + v + 1] += psh[V][v];
//    }
//
//    psh[V][v] = 0;
//}
//void upd(int V, int v, int tl, int tr, int l, int r, int L, int R)
//{
//    Push(V, v, tl, tr, L, R);
//
//    if (r < tl || tr < l) return;
//
//    if (l <= tl && tr <= r) {psh[V][v]++; Push(V, v, tl, tr, L, R); return;}
//
//    int md = (tl + tr) >> 1;
//
//    upd(V, v + v, tl, md, l, r, L, R);
//
//    upd(V, v + v + 1, md + 1, tr, l, r, L, R);
//
//    t[V][v] = t[V][v + v] + t[V][v + v + 1];
//}
//
//void Pushr(int v, int tl, int tr)
//{
//    while (sz(pshr[v]) > 0)
//    {
//        pair <int, int> p = pshr[v].back();
//
//        pshr[v].pop_back();
//
//        upd(v, 1, 0, m - 1, p.F, p.S, tl, tr);
//
//        if (tl != tr)
//        {
//            pshr[v + v].pb(p);
//
//            pshr[v + v + 1].pb(p);
//        }
//    }
//}
//void upd_f(int v, int tl, int tr, int l, int r, int L, int R)
//{
//    Pushr(v, tl, tr);
//
//    if (tr < l || r < tl) return;
//
//    if (l <= tl && tr <= r) {pshr[v].pb({L, R}); Pushr(v, tl, tr);}
//
//    else
//    {
//        int md = (tl + tr) >> 1;
//
//        upd_f(v + v, tl, md, l, r, L, R);
//
//        upd_f(v + v + 1, md + 1, tr, l, r, L, R);
//
//        t[v][1] = t[v + v][1] + t[v + v + 1][1];
//    }
//}

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

ll ans;

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++)
          for (int b = 1; b <= m - j; 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];

                if (sm != 0) break;

                ans += a * b;

                //cout << i << " " << j << " " << i + a - 1 << " " << j + b - 1 << endl;

                //upd_f(1, 0, n - 1, i, i + a - 1, j, j + b - 1);


           }

    cout << ans << endl;
}

Compilation message

strah.cpp: In function 'int main()':
strah.cpp:132:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    for (int i = 0; i < n; i++)
    ^~~
strah.cpp:156:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
     cout << ans << endl;
     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 896 KB Output is correct
2 Correct 68 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 896 KB Output is correct
2 Correct 57 ms 920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 3788 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 6784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 4864 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 12 ms 2048 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 9984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -