結果

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

テストケース

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

ソースコード

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