結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2020-02-14 23:49:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,537 bytes |
| コンパイル時間 | 2,846 ms |
| コンパイル使用メモリ | 186,228 KB |
| 実行使用メモリ | 814,736 KB |
| 最終ジャッジ日時 | 2024-11-16 01:50:17 |
| 合計ジャッジ時間 | 7,153 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 RE * 1 MLE * 1 |
ソースコード
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
for(T& x:vec) is >> x;
return is;
}
const ll INF=1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main()
{
ll n,m,k;
cin >> n >> m >> k;
char op;
cin >> op;
vector<ll> b(m);
vector<ll> a(n);
rep(i,m){
cin >> b[i];
}
rep(i,n){
cin >> a[i];
}
ll ans=0;
//行ごとに二分探索
if(op=='+'){
vector<ll> s(k); //aをkで割った余りを入れる
vector<ll> t(k); //b
rep(i,n){
s[a[i]%k]++;
}
rep(i,m){
t[b[i]%k]++;
}
ans+=s[0]*t[0];
rep(i,k-1){
ans+=s[i+1]*t[k-i-1];
}
cout << ans << endl;
}
else{
map<ll,ll> mp_a;
map<ll,ll> mp_b;
rep(i,n){
mp_a[gcd(a[i],k)]++;
}
rep(i,m){
mp_b[gcd(b[i],k)]++;
}
for(auto x:mp_a){
for(auto y:mp_b){
if(x.first*y.first%k==0){
ans+=x.second*y.second;
}
}
}
cout << ans << endl;
}
return 0;
}
kyoprouno