結果

問題 No.989 N×Mマス計算(K以上)
ユーザー kyoprounokyoprouno
提出日時 2020-02-14 22:46:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,660 bytes
コンパイル時間 2,519 ms
コンパイル使用メモリ 178,476 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 02:45:06
合計ジャッジ時間 3,567 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

int main()
{
    ll n,m,k;
    cin >> n >> m >> k;
    char op;
    cin >> op;
    vector<ll> b(m);
    vector<ll> a(n);
    rep(i,m){
        cin >> b[i];
    }
    rep(i,n){
        cin >> a[i];
    }
    sort(b.begin(),b.end());
    sort(a.begin(),a.end());
    ll ans=0;
    //行ごとに二分探索
    if(op=='+'){
        rep(i,n){
            ll left=-1;
            ll right=m;
            while(right-left>1){
                ll mid=(right+left)/2;
                ll v=a[i]+b[mid];
                if(v>=k){
                    right=mid;
                }
                else{
                    left=mid;
                }
            }
            ans+=m-(left+1);
            
        }
        cout << ans << endl;
    }
    else{
        rep(i,n){
            ll left=-1;
            ll right=m;
            while(right-left>1){
                ll mid=(right+left)/2;
                ll v=a[i]*b[mid];
                if(v>=k){
                    right=mid;
                }
                else{
                    left=mid;
                }
            }
            ans+=m-(left+1);
        }
        cout << ans <<endl;
    }
    
    return 0;
} 
0