結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-02-14 23:52:38
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,074 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 133,604 KB
実行使用メモリ 359,712 KB
最終ジャッジ日時 2024-05-07 20:24:57
合計ジャッジ時間 4,749 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 19 ms
5,376 KB
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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