結果

問題 No.989 N×Mマス計算(K以上)
ユーザー msm1993msm1993
提出日時 2020-04-02 17:02:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 170,700 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:31:27
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,k;
    std::cin >> n>>m>>k;
    
    char op;
    std::cin >> op;
    vector<ll> a(n),b(m);
    
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if(op=='+'){
            ans += m-distance(b.begin(),lower_bound(b.begin(),b.end(),k-a[i]));
        }else{
            ll r = m;
            ll l = -1;
            while(r-l>1){
                ll mid = (r+l)/2;
                if(b[mid]*a[i]>=k){
                    r = mid;
                }else{
                    l = mid;
                }
            }
            ans += m-r;
        }
    }
    std::cout << ans << std::endl;
}

0