結果

問題 No.866 レベルKの正方形
ユーザー DAyamaCTFDAyamaCTF
提出日時 2019-08-16 23:46:09
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,107 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 166,420 KB
実行使用メモリ 289,344 KB
最終ジャッジ日時 2023-10-24 07:23:15
合計ジャッジ時間 10,641 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
97,656 KB
testcase_01 AC 36 ms
97,656 KB
testcase_02 AC 37 ms
97,656 KB
testcase_03 AC 36 ms
97,656 KB
testcase_04 AC 37 ms
97,656 KB
testcase_05 AC 36 ms
97,656 KB
testcase_06 AC 36 ms
97,656 KB
testcase_07 AC 36 ms
97,656 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:44:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |   scanf("%d%d%d",&H,&W,&K);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |     scanf("%s",S);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

const int n=26;

vector<unsigned char> operator+(const vector<unsigned char>& a,const vector<unsigned char>& b){
  vector<unsigned char> c(n,0);
  rep(i,n)c[i]=a[i]+b[i];
  return c;
}
vector<unsigned char> operator-(const vector<unsigned char>& a,const vector<unsigned char>& b){
  vector<unsigned char> c(n,0);
  rep(i,n)c[i]=a[i]-b[i];
  return c;
}

int H,W,K;
char S[2001];
vector<unsigned char> sum[2001][2001];

int main(){

  scanf("%d%d%d",&H,&W,&K);
  rep(i,H){
    scanf("%s",S);
    rep(j,W){
      vector<unsigned char> crt(n,0);
      crt[S[j]-'a']++;
      sum[i+1][j+1]=crt;
    }
  }
  rep(i,H+1)rep(j,W+1){
    if(sum[i][j].size()==0)sum[i][j]=vector<unsigned char>(n,0);
  }

  rep(i,H+1)rep(j,W)sum[i][j+1]=sum[i][j+1]+sum[i][j];
  rep(i,H)rep(j,W+1)sum[i+1][j]=sum[i+1][j]+sum[i][j];

  ll res=0;
  rep(i,H)rep(j,W){
    ll add=0;
    {
      int lb=0,ub=min(W-j,H-i)+1;
      while(ub-lb>1){
        int X=(ub+lb)/2;
        vector<unsigned char> crt=sum[i+X][j+X]-sum[i][j+X]-sum[i+X][j]+sum[i][j];
        int cnt=0;
        rep(k,n)if(crt[k]>0)cnt++;
        if(cnt>=K) ub=X;
        else lb=X;
      }
      add-=ub;
    }
    {
      int lb=0,ub=min(W-j,H-i)+1;
      while(ub-lb>1){
        int X=(ub+lb)/2;
        vector<unsigned char> crt=sum[i+X][j+X]-sum[i][j+X]-sum[i+X][j]+sum[i][j];
        int cnt=0;
        rep(k,n)if(crt[k]>0)cnt++;
        if(cnt>=K+1) ub=X;
        else lb=X;
      }
      add+=ub;
    }
    res+=(ll)(add);
  }
  cout<<res<<endl;

  return 0;
}
0