結果

問題 No.1994 Confusing Name
ユーザー kzyKTkzyKT
提出日時 2022-07-01 21:44:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 2,028 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 159,104 KB
実行使用メモリ 25,988 KB
最終ジャッジ日時 2023-08-17 09:13:24
合計ジャッジ時間 11,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 440 ms
18,032 KB
testcase_13 AC 631 ms
24,432 KB
testcase_14 AC 715 ms
25,236 KB
testcase_15 AC 569 ms
21,760 KB
testcase_16 AC 476 ms
19,344 KB
testcase_17 AC 553 ms
21,248 KB
testcase_18 AC 753 ms
25,600 KB
testcase_19 AC 764 ms
25,988 KB
testcase_20 AC 769 ms
25,788 KB
testcase_21 AC 73 ms
7,680 KB
testcase_22 AC 30 ms
5,544 KB
testcase_23 AC 529 ms
21,676 KB
testcase_24 AC 494 ms
20,952 KB
testcase_25 AC 268 ms
14,768 KB
testcase_26 AC 108 ms
9,192 KB
testcase_27 AC 460 ms
19,812 KB
testcase_28 AC 316 ms
15,800 KB
testcase_29 AC 25 ms
5,228 KB
testcase_30 AC 353 ms
16,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<unsigned long long,unsigned long long> P;

struct RH {
  vector<unsigned long long> p,hash;
  void init(const string s) {
    unsigned long long m=1000000007,n=s.size();
    p.resize(n+1);hash.resize(n+1);p[0]=1;hash[0]=0;
    rep(i,n)p[i+1]=p[i]*m,hash[i+1]=s[i]+hash[i]*m;
  }
  unsigned long long h(int i)const{return hash[i];}
  unsigned long long h(int i,int j)const{return h(j)-h(i)*p[j-i];}
};

void Main() {
  ll n;
  cin >> n;
  string s[n];
  rep(i,n) cin >> s[i];
  map<P,ll> m[11][11];
  ll d[n];
  mem(d);
  rep(i,n) {
    RH r;
    r.init(s[i]);
    rep(j,s[i].size()) {
      P p=P(r.h(j),r.h(j+1,s[i].size()));
      d[i]+=m[s[i].size()][j][p];
    }
    rep(j,s[i].size()) {
      P p=P(r.h(j),r.h(j+1,s[i].size()));
      m[s[i].size()][j][p]++;
    }
  }
  rep(i,11)rep(j,11) m[i][j].clear();
  rrep(i,n) {
    RH r;
    r.init(s[i]);
    rep(j,s[i].size()) {
      P p=P(r.h(j),r.h(j+1,s[i].size()));
      d[i]+=m[s[i].size()][j][p];
    }
    rep(j,s[i].size()) {
      P p=P(r.h(j),r.h(j+1,s[i].size()));
      m[s[i].size()][j][p]++;
    }
  }
  rep(i,n) pr(d[i]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0