結果

問題 No.206 数の積集合を求めるクエリ
ユーザー Tsuneo YoshiokaTsuneo Yoshioka
提出日時 2015-05-08 23:43:59
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 988 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 66,672 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-19 08:57:22
合計ジャッジ時間 10,396 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,432 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 29 ms
4,376 KB
testcase_17 AC 68 ms
4,376 KB
testcase_18 AC 35 ms
4,376 KB
testcase_19 AC 62 ms
4,380 KB
testcase_20 AC 35 ms
4,376 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 43 ms
4,380 KB
testcase_23 AC 64 ms
4,380 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int calc(vector<int> &A, vector<int> &B, int v)
{
    int AN = (int)A.size(), BN = (int)B.size();
    int ap = 0, bp = 0;
    int count = 0;
    while(ap<AN && bp<BN){
        if(A[ap]==B[bp]+v){
        // cout << "ap=" << ap << ",bp=" << bp << endl;
            ap++, bp++;
            count ++;
        }else if(A[ap]>B[bp]+v){
            bp++;
        }else{
            ap++;
        }
    }
    return count;
}
int main(void){
    // Here your code !
    int L, M, N;
    cin >> L >> M >> N;
    vector<int> A, B;
    for(int l=0;l<L;l++){
        int val;
        cin >> val;
        A.push_back(val);
    }
    for(int m=0;m<M;m++){
        int val;
        cin >> val;
        B.push_back(val);
    }
    int Q;
    cin >> Q;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    for(int v=0;v<Q;v++){
        int ret = calc(A, B, v);
        cout << ret << endl;
    }
    return 0;
}
0