Submission #516141

# Submission time Handle Problem Language Result Execution time Memory
516141 2022-01-20T12:44:52 Z thanh913 Strah (COCI18_strah) C++14
44 / 110
1000 ms 37648 KB
#include <bits/stdc++.h>
using namespace std;

//types
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)

//lowercase 31, all 53
//(P/Q) % M = (P % M) * (Q^(M-2) % M)
//-------------------------------------------------------

const ll mx = 5e3+5, mod = 1e9+7;
int n, m, ans = 0, s[mx][mx];
bool a[mx][mx];

int tong(int r1, int c1, int r2, int c2) 
{
	return s[r2][c2] - s[r2][c1-1] - s[r1-1][c2] + s[r1-1][c1-1];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
    	for (int j = 1; j <= m; j++) 
    	{
    		char tmp;
    		cin >> tmp;
    		a[i][j] = (tmp == '.') ? 0 : 1;
    		s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
    	}

    for (int i = 1; i <= n; i++) 
    {
    	for (int j = 1; j <= m; j++) 
    	{
    		int h = n;
    		for (int k = j; k <= m; k++) 
    		{
    			while (h >= i) 
    			{
    				if (tong(i, j, h, k) == 0) break;
    				h--;
    			}
    			if (h >= i) 
    			{
    				int sc = k - j + 1, sr = h - i + 1;
    				ans += sr * (sr+1) / 2 * sc;
    			}
    		}
    	}
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 3276 KB Output is correct
2 Correct 43 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 3284 KB Output is correct
2 Correct 52 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 3280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 12792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 24152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1031 ms 15476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 774 ms 16504 KB Output is correct
2 Execution timed out 1043 ms 31368 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1028 ms 37648 KB Time limit exceeded
2 Halted 0 ms 0 KB -