結果

問題 No.866 レベルKの正方形
ユーザー tnakao0123tnakao0123
提出日時 2019-08-19 15:27:11
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,580 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 85,784 KB
実行使用メモリ 416,688 KB
最終ジャッジ日時 2024-04-15 02:22:48
合計ジャッジ時間 9,482 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,760 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |   scanf("%d%d%d", &h, &w, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:66:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   66 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~

ソースコード

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;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_W + 4];
int css[26][MAX_H + 1][MAX_W + 1];

/* subroutines */

inline int stlb(int i, int j, int maxl, int k) {
  int l0 = 0, l1 = maxl + 1;
  while (l0 + 1 < l1) {
    int l = (l0 + l1) / 2;

    int num = 0;
    for (int c = 0; c < 26; c++)
      if (css[c][i + l][j + l] - css[c][i + l][j] - css[c][i][j + l]
	  + css[c][i][j] > 0) num++;

    if (num >= k) l1 = l;
    else l0 = l;
  }
  return l1;
}

/* main */

int main() {
  int h, w, k;
  scanf("%d%d%d", &h, &w, &k);

  for (int i = 0; i < h; i++) {
    scanf("%s", s);
    for (int j = 0; j < w; j++) {
      int cij = s[j] - 'a';
      for (int c = 0; c < 26; c++)
	css[c][i + 1][j + 1] =
	  ((cij == c) ? 1 : 0)
	  + css[c][i + 1][j] + css[c][i][j + 1] - css[c][i][j];
    }
  }

  ll sum = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      int maxl = min(h - i, w - j);
      int l0 = stlb(i, j, maxl, k);
      if (l0 <= maxl) {
	int l1 = stlb(i, j, maxl, k + 1);
	sum += l1 - l0;
      }
    }

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