結果
問題 | No.866 レベルKの正方形 |
ユーザー |
![]() |
提出日時 | 2019-08-17 00:08:53 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,147 ms / 6,000 ms |
コード長 | 2,965 bytes |
コンパイル時間 | 999 ms |
コンパイル使用メモリ | 114,764 KB |
実行使用メモリ | 414,148 KB |
最終ジャッジ日時 | 2024-09-23 04:52:46 |
合計ジャッジ時間 | 28,849 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#define _USE_MATH_DEFINES#include <iostream>#include <fstream>#include <sstream>#include <string>#include <cstring>#include <vector>#include <set>#include <map>#include <unordered_map>#include <queue>#include <deque>#include <stack>#include <algorithm>#include <bitset>#include <cmath>#include <cstdlib>#include <ctime>#include <numeric>#include <functional>#include <cctype>#include <list>#include <limits>#include <cassert>#include <random>#include <time.h>//#include <boost/multiprecision/cpp_int.hpp>using namespace std;using Int = long long;//using namespace boost::multiprecision;const double EPS = 1e-10;long long const MOD = 1000000007;long long mod_pow(long long x, long long n) {long long res = 1;for (int i = 0;i < 60; i++) {if (n >> i & 1) res = res * x % MOD;x = x * x % MOD;}return res;}template<typename T>T gcd(T a, T b) {return b != 0 ? gcd(b, a % b) : a;}template<typename T>T lcm(T a, T b) {return a * b / gcd(a, b);}void fastInput() {cin.tie(0);ios::sync_with_stdio(false);}vector<long long> Divisor(long long n) {vector<long long> ret;for(long long i=1; i*i<=n; i++) {if(n % i == 0) {ret.push_back(i);if(i*i!=n) ret.push_back(n / i);}}return ret;}int ruiseki[2001][2001][26];char field[2001][2001];int H, W, K;int calc(int lw, int lh, int rw, int rh) {int ret = 0;for (int i = 0; i < 26; i++) {int a = ruiseki[rh][rw][i] + ruiseki[lh-1][lw-1][i];a -= ruiseki[lh-1][rw][i];a -= ruiseki[rh][lw-1][i];if (a > 0) ret++;}return ret;}int shakutori(int sW, int sH, int N) {int lw = sW;int lh = sH;int rw = sW;int rh = sH;long long ret = 0;for (; lw <= W && lh <= H; lw++, lh++) {while (rw <= W && rh <= H && calc(lw, lh, rw, rh) <= N) {rw++;rh++;}ret += rw - lw;if (rw < lw) {rw++;rh++;}}return ret;}int main(void) {cin >> H >> W >> K;for (int i = 1; i <= H; i++) {for (int j = 1; j <= W; j++) {cin >> field[i][j];}}for (int i = 1; i <= H; i++) {for (int j = 1; j <= W; j++) {ruiseki[i][j][field[i][j] - 'a']++;for (int k = 0; k < 26; k++) {ruiseki[i][j][k] += ruiseki[i][j-1][k];}}}for (int i = 1; i <= H; i++) {for (int j = 1; j <= W; j++) {for (int k = 0; k < 26; k++) {ruiseki[i][j][k] += ruiseki[i-1][j][k];}}}long long ans = 0;for (int i = 1; i <= W; i++) {ans += shakutori(i, 1, K) - shakutori(i, 1, K-1);}for (int i = 2; i <= H; i++) {ans += shakutori(1, i, K) - shakutori(1, i, K-1);}cout << ans << endl;}