結果

問題 No.866 レベルKの正方形
ユーザー b312546656b312546656
提出日時 2019-08-16 23:49:57
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 3,052 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 93,976 KB
実行使用メモリ 348,028 KB
最終ジャッジ日時 2023-10-24 09:38:37
合計ジャッジ時間 31,865 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define vel vector<short>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

template<typename T>
V<T> uni(V<T> &v) {
	if (v.size() == 0) { return v; }
	sor(v);
	V<T> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	a = abs(a);
	b = abs(b);
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
int solve(int sum, int lim) {
	if (sum <= lim) { return sum - 1; }
	if (sum > lim * 2) { return 0; }
	return lim * 2 - sum+1;
}
signed main() {
	int h, w, le; cin >> h >> w >> le; le--;
	V<vvel> a(h+1,vvel(w+1,vel(27,2010)));
	if (h*w <= 400) {
		le++;
		int ans = 0;
		V<string> s(h);
		rep(i, h) { cin >> s[i]; }
		rep(i, h) {
			rep(j, w) {
				rep(k, min(h - i, w - j)+1) {
					vel count(26,0);
					int count_ans = 0;
					rep(l, k) {
						rep(m, k) {
							int val = s[i + l][j + m] - 'a';
							if (count[val] == 0) { count_ans++; }
							count[val]++;
						}
					}
					if (count_ans == le) { ans++; }
				}
			}
		}
		cout << ans << endl;
		return 0;
	}
	RE();
	rep(i, h) {
		string s; cin >> s;
		rep(j, w) {
			int val = s[j] - 'a';
			a[i][j][val] = 0;
		}
	}
	short x = 1;
	rep(k, 26) {
		for(int i=h-1;i>=0;i--) {
			for(int j=w-1;j>=0;j--) {
				short st = min(min(a[i + 1][j + 1][k], a[i][j + 1][k]), a[i + 1][j][k]) + x;
				mmin(a[i][j][k], st);
			}
		}
	}
	int ans = 0;
	rep(i, h) {
		rep(j, w) {
			sor(a[i][j]);
			int l1 = a[i][j][le];
			int l2 = a[i][j][le + 1];
			int dis = min(h - i, w - j);
			if (l1 != 2010) {
				mmin(l2, dis);
				ans += l2 - l1;
			}
		}
	}
	cout << ans << endl;
}
0