結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー yukarinokiyukarinoki
提出日時 2020-02-15 06:41:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,056 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 114,740 KB
実行使用メモリ 5,012 KB
最終ジャッジ日時 2023-08-10 03:09:03
合計ジャッジ時間 3,583 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

long long int gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(b==0) return 0;
    if(a%b == 0) return b;
    else return gcd(b,a%b); 
}

int main(){
    long long int n,m,k; cin >> n >> m >> k;
    string s; cin >> s;
    vector<long long int> v(m); rep(i,m) cin >> v[i];
    vector<long long int> a(n); rep(i,n) cin >> a[i];
    rep(i,m) v[i] %= k;
    rep(i,n) a[i] %= k;
    sort(all(a));
    sort(all(v));
    long long int ans = 0;
    if(s=="+") for(int i=0;i<m;i++){
        if(binary_search(all(a), (k-v[i])%k)){
            int id = lower_bound(all(a), (k-v[i])%k) - a.begin();
            int idd = upper_bound(all(a), (k-v[i])%k) - a.begin();
            ans = ans + idd - id;
        }
    }else{
        map<long long int,long long int> vm,am;
        rep(i,m){
            int gc = gcd(v[i], k);
            if(vm.count(gc)==0) vm[gc] = 1;
            else vm[gc]++;
        }
        rep(i,n){
            int gc = gcd(a[i], k);
            if(am.count(gc)==0) am[gc] = 1;
            else am[gc]++;
        }
        for(const auto& [key,val]: vm){
            for(auto [kk,vv]: am){              
                if((key*kk) % k == 0){
                    cout << vv << " " << val << endl;
                    ans = ans + (val*vv);
                }
            }
        }
    }      
    cout << ans << endl;

    return 0;
}
0