답안 #474418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474418 2021-09-18T08:25:56 Z Killer2501 Strah (COCI18_strah) C++14
110 / 110
164 ms 35664 KB
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 2e3+5;
const ll mod = 1e9 + 7;
const int base = 40;
ll n, m, k, t, a[N][N], b[N], tong, dp[N], lab[N], st[N*4], lazy[N*4], ans;
char c;
vector<ll> adj[N], kq;
pll p[N];
ll pw(ll k, ll n)
{
	ll total = 1;
	for(; n; n >>= 1)
	{
		if(n & 1)total = total * k % mod;
		k = k * k % mod;
	}
	return total;
}

ll findp(ll u)
{
	return lab[u] < 0 ? u : lab[u] = findp(lab[u]);
}
void hop(ll u, ll v)
{
	if(lab[u] > lab[v])swap(u, v);
	lab[u] += lab[v];
	lab[v] = u;

}

void sol()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	{
		tong = 0;
		k = 0;
		kq.clear();
		for(int j = 1; j <= m; j ++)
		{
			cin >> c;
			if(c == '.')a[i][j] = a[i-1][j] + 1;
			while(!kq.empty() && a[i][j] < a[i][kq.back()])
			{
				ll r = kq.back();
				kq.pop_back();
				ll l = kq.empty() ? 0 : kq.back();
                tong -= (r-l) * (r-1+l) / 2 * a[i][r] * (a[i][r] + 1) / 2;
                k -= (r-l) * a[i][r] * (a[i][r]+1)/2;
			}
			ll l = kq.empty() ? 0 : kq.back();
			k += (j-l) * a[i][j] * (a[i][j] + 1) / 2;
			tong += (j-l) * (j-1+l) / 2 * a[i][j] * (a[i][j] + 1) / 2;
			ans += j * k - tong;
			kq.pb(j);
			//cout << j*k-tong <<" ";
		}
		//cout << '\n';
	}
	cout << ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int test = 1;
    //cin >> test;
    while (test-- > 0)
        sol();
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2380 KB Output is correct
2 Correct 4 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2380 KB Output is correct
2 Correct 6 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2356 KB Output is correct
2 Correct 5 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 12916 KB Output is correct
2 Correct 107 ms 26424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 23612 KB Output is correct
2 Correct 149 ms 34372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 15164 KB Output is correct
2 Correct 103 ms 28108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 9932 KB Output is correct
2 Correct 124 ms 32704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 35652 KB Output is correct
2 Correct 164 ms 35664 KB Output is correct