結果
問題 |
No.990 N×Mマス計算(Kの倍数)
|
ユーザー |
![]() |
提出日時 | 2021-03-16 23:31:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 1,117 bytes |
コンパイル時間 | 3,807 ms |
コンパイル使用メモリ | 259,076 KB |
最終ジャッジ日時 | 2025-01-19 17:40:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; typedef pair<ll,ll> P; typedef modint1000000007 mint; #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,a,b) for(ll i=a;i>=b;i--) const ll inf=1e18; ll gcd(ll a,ll b){ if(b%a==0) return a; else return gcd(b%a,a); } ll n,m,k; char op; ll a[100005],b[100005]; ll A[100005],B[100005]; ll ans; int main(void){ cin.tie(0); ios::sync_with_stdio(0); cin>>n>>m>>k; cin>>op; map<ll,ll> M,M2; rep(i,0,m){ cin>>a[i]; A[i]=gcd(a[i],k); M[A[i]]++; a[i]%=k; } rep(i,0,n){ cin>>b[i]; B[i]=gcd(b[i],k); M2[B[i]]++; b[i]%=k; } sort(a,a+m); sort(b,b+n); if(op=='+'){ rep(i,0,m){ ans+=(upper_bound(b,b+n,(k-a[i])%k)-lower_bound(b,b+n,(k-a[i])%k)); } }else{ for(auto& i:M){ for(auto& j:M2){ if(i.first*j.first%k==0){ ans+=i.second*j.second; } } } } cout<<ans<<endl; }