結果
問題 |
No.990 N×Mマス計算(Kの倍数)
|
ユーザー |
![]() |
提出日時 | 2020-04-10 20:46:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 1,125 bytes |
コンパイル時間 | 2,330 ms |
コンパイル使用メモリ | 206,556 KB |
最終ジャッジ日時 | 2025-01-09 15:49:27 |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> #define ALL(v) std::begin(v),std::end(v) using lint=long long; using ld=long double; int main(){ std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false); std::cout.setf(std::ios_base::fixed);std::cout.precision(15); lint n,m,k;std::cin>>n>>m>>k; char c;std::cin>>c; std::vector<lint>a(n),b(m); for(lint&y:b)std::cin>>y; for(lint&x:a)std::cin>>x; lint ans=0; if(c=='+'){ std::map<lint,lint>map; for(lint y:b)map[y%k]++; for(lint x:a){ x%=k; ans+=map[x?k-x:0]; } }else{ std::vector<lint>divs; for(lint i=1;i*i<=k;i++){ if(k%i)continue; divs.push_back(i); if(i*i!=k)divs.push_back(k/i); } std::map<lint,lint>map; for(lint y:b){ map[std::gcd(k,y)]++; } for(auto[d,mu]:map){ for(lint e:divs){ if(d==e||d%e)continue; map[e]+=mu; } } for(lint x:a){ ans+=map[k/std::gcd(k,x)]; } } std::cout<<ans<<'\n'; }