結果

問題 No.1788 Same Set
ユーザー beet
提出日時 2021-12-17 00:37:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,099 bytes
コンパイル時間 2,531 ms
コンパイル使用メモリ 205,264 KB
最終ジャッジ日時 2025-01-27 00:00:18
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 8 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

// multiset dato godoku sita

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
const Int MAX = 4e5+10;
const Int T = 10;
Int rnd[T][MAX];


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;

  auto as=read(n);
  auto bs=read(n);

  random_device seed;
  mt19937 mt(seed());
  uniform_int_distribution<Int> ud(1,1e9);

  for(Int t=0;t<T;t++)
    for(Int i=0;i<MAX;i++)
      rnd[t][i]=ud(mt);

  using A = array<Int, T>;
  map<A, Int> cnt;
  A sum;
  fill(sum.begin(),sum.end(),0);

  Int ans=0;
  for(Int i=0;i<n;i++){
    cnt[sum]++;
    for(Int t=0;t<T;t++)
      sum[t]+=rnd[t][as[i]]-rnd[t][bs[i]];
    ans+=cnt[sum];
  }

  cout<<ans<<endl;
  return 0;
}
0