結果

問題 No.866 レベルKの正方形
ユーザー tnakao0123tnakao0123
提出日時 2019-08-19 17:49:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,014 ms / 6,000 ms
コード長 1,588 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 88,432 KB
実行使用メモリ 414,172 KB
最終ジャッジ日時 2024-04-15 05:00:04
合計ジャッジ時間 24,796 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,876 KB
testcase_01 AC 2 ms
7,748 KB
testcase_02 AC 3 ms
7,628 KB
testcase_03 AC 2 ms
7,624 KB
testcase_04 AC 2 ms
7,756 KB
testcase_05 AC 2 ms
7,624 KB
testcase_06 AC 3 ms
7,752 KB
testcase_07 AC 2 ms
6,948 KB
testcase_08 AC 2,014 ms
413,996 KB
testcase_09 AC 1,352 ms
414,168 KB
testcase_10 AC 1,163 ms
413,996 KB
testcase_11 AC 1,791 ms
414,112 KB
testcase_12 AC 1,436 ms
413,980 KB
testcase_13 AC 1,838 ms
414,144 KB
testcase_14 AC 1,461 ms
414,164 KB
testcase_15 AC 1,728 ms
414,172 KB
testcase_16 AC 1,633 ms
414,116 KB
testcase_17 AC 1,464 ms
414,124 KB
testcase_18 AC 1,749 ms
414,060 KB
testcase_19 AC 1,857 ms
414,112 KB
testcase_20 AC 1,560 ms
413,984 KB
testcase_21 AC 532 ms
413,980 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 3 ms
9,668 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:53:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |   scanf("%d%d%d", &h, &w, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:54:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |   for (int i = 0; i < h; i++) scanf("%s", flds[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 866.cc:  No.866 レベルKの正方形 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 2000;
const int MAX_W = 2000;
const int INF = 1 << 29;

/* typedef */

typedef long long ll;

/* global variables */

char flds[MAX_H][MAX_W + 4];
int dp[MAX_H + 1][MAX_W + 1][26];

/* subroutines */

inline int min3(int a, int b, int c) {
  if (a < b) return (a < c) ? a : c;
  return (b < c) ? b : c;
}

/* main */

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);
  for (int i = 0; i < h; i++) scanf("%s", flds[i]);

  for (int i = h; i >= 0; i--)
    for (int j = w; j >= 0; j--) {
      if (i == h || j == w)
	fill(dp[i][j], dp[i][j] + 26, INF);
      else {
	int cij = flds[i][j] - 'a';
	for (int c = 0; c < 26; c++) {
	  if (c == cij)
	    dp[i][j][c] = 1;
	  else
	    dp[i][j][c] =
	      min3(dp[i][j + 1][c], dp[i + 1][j][c], dp[i + 1][j + 1][c])
	      + 1;
	}
      }
    }

  ll sum = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      int *as = dp[i][j];
      sort(as, as + 26);

      int maxl = min(h - i, w - j);
      int a0 = as[k - 1];
      if (a0 <= maxl) {
	int a1 = min(maxl + 1, (k >= 26) ? INF : as[k]);
	sum += a1 - a0;
      }
    }

  printf("%lld\n", sum);
  return 0;
}
0