結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2020-02-05 01:36:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 671 bytes |
コンパイル時間 | 2,434 ms |
コンパイル使用メモリ | 206,732 KB |
最終ジャッジ日時 | 2025-01-08 22:09:31 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll=long long;int gcd(int a,int b){return a?gcd(b%a,a):b;}int main(){cin.tie(0);ios::sync_with_stdio(false);int N,M,K;cin>>N>>M>>K;string op;cin>>op;ll z=0;if(op=="+"){map<int,int>m;for(int i=0;i<M;++i){int B;cin>>B;++m[B%K];}for(int i=0;i<N;++i){int A;cin>>A;z+=m[(K-A%K)%K];}}else{map<ll,ll>ma,mb;for(int i=0;i<M;++i){int B;cin>>B;++mb[gcd(K,B)];}for(int i=0;i<N;++i){int A;cin>>A;++ma[gcd(K,A)];}for(auto a:ma){for(auto b:mb){if(a.first*b.first%K==0){z+=a.second*b.second;}}}}cout<<z<<"\n";return 0;}