結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー zeronosu77108
提出日時 2020-02-14 23:52:38
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,074 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 132,060 KB
実行使用メモリ 380,544 KB
最終ジャッジ日時 2024-11-30 16:24:35
合計ジャッジ時間 11,090 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10 WA * 6 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>

using namespace std;

using int64 = long long;
using P = pair<int64,int64>;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int64 n,m,k;
    cin >> n >> m >> k;
    char op; cin >> op; bool plus = op == '+';

    vector<int64> a(n);
    vector<int64> b(m);
    for (int64 i=0; i<m; i++) cin >> b[i];
    for (int64 i=0; i<n; i++) cin >> a[i];

    if (plus) {
        for (int i=0; i<m; i++) b[i] %= k;
        for (int i=0; i<n; i++) a[i] %= k;
    }
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());


    int64 ans = 0;
    if (plus) {

        for (int i=0; i<n; i++) {
            ans += upper_bound(b.begin(),b.end(), k - a[i]) - lower_bound(b.begin(),b.end(), k-a[i]);
        }
    } else {
        map<int64,int64> mp;
        for (int i=0; i<n; i++) { mp[gcd(k,a[i])]++; }
        for (int i=0; i<m; i++) {
            int s = k / gcd(k, b[i]);
            for (int j=s; j<k; j+=s) ans += mp[j];
        }
    }

    cout << ans << endl;
}
0