結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 20 ms
6,944 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>

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];
        b[i] %= k;
    }
    for (int64 i=0; i<n; i++) {
        cin >> a[i];
        a[i] %= k;
    }
    sort(b.begin(), b.end());
    sort(a.begin(), a.end());

    vector<P> la; la.emplace_back(a[0],0);
    for (int64 i=0; i<n; i++) {
        if (la.back().first == a[i]) la.back().second++;
        else la.emplace_back(a[i], 1);
    }

    vector<P> lb; lb.emplace_back(b[0],0);
    for (int64 i=0; i<m; i++) {
        if (lb.back().first == b[i]) lb.back().second++;
        else lb.emplace_back(b[i], 1);
    }
//
//    for (auto [ai, ac] : la) cout << ai << " " << ac << endl;
//    for (auto [bi, bc] : lb) cout << bi << " " << bc << endl;

    int64 ans = 0;
    if (plus) {
        for (auto [ai, ac] : la) {
            auto it = lower_bound(lb.begin(), lb.end(), P(k-ai,0) );
            if (it == lb.end()) continue;
            auto [bi, bc] = *it;
            if (bi == k - ai) ans += ac * bc;
        }
    } else {
        if (la[0].first == 0) ans += la[0].second * m;
        if (lb[0].first == 0) ans += lb[0].second * n;

        for (auto [ai, ac] : la) {
            if (ai == 0) continue;
            int64 s = k / gcd(k, ai);
            for (int j = s; j < k; j += s) {
                auto it = lower_bound(lb.begin(), lb.end(), P(j, 0));
                if (it == lb.end()) continue;
                auto[bi, bc] = *it;
                if (bi == j) ans += ac * bc;
            }
        }
    }

    cout << ans << endl;
}
0