提出 #71846786


ソースコード 拡げる

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
#include <functional>
#include <random>


using namespace std;
#define ll long long
#define MOD 998244353
#define ld long double
#define INF 2251799813685248
#define vall(A) A.begin(),A.end()
#define gridinput(vv,H,W) for (ll i = 0; i < H; i++){string T; cin >> T; for(ll j = 0; j < W; j++){vv[i][j] = {T[j]};}}
#define adjustedgridinput(vv,H,W) for (ll i = 1; i <= H; i++){string T; cin >> T; for(ll j = 1; j <= W; j++){vv[i][j] = {T[j-1]};}}
#define vin(A) for (ll i = 0, sz = A.size(); i < sz; i++){cin >> A[i];}
#define vout(A) for(ll i = 0, sz = A.size(); i < sz; i++){cout << A[i] << " \n"[i == sz-1];}
#define vsum(A) [&](const auto &vveecc){ll ssuumm = 0; for(auto &vvaalluuee : vveecc){ssuumm += vvaalluuee;} return ssuumm;}(A)
#define adjustedvin(A) for (ll i = 1, sz = A.size(); i < sz; i++){cin >> A[i];}
#define adjustedvout(A) for(ll i = 1, sz = A.size(); i < sz; i++){cout << A[i] << " \n"[i == sz-1];}
#define vout2d(A,H,W) for (ll i = 0; i < H; i++){for (ll j = 0; j < W; j++){cout << A[i][j] << " \n"[j==W-1];}}
#define encode(i,j) ((i)<<32)+j
#define decode(v,w) (w ? (v)%4294967296 : (v)>>32)
vector<ll> pow2ll{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296};
vector<ll> pow10ll{1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000};
vector<ll> di{0,1,0,-1};
vector<ll> dj{1,0,-1,0};




int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N+1);
    vector<ll> B(M+1);
    adjustedvin(A);
    adjustedvin(B);
    sort(vall(A));
    sort(vall(B));

    vector<ll> ruisekiB = B;
    for (ll i = 1; i <= M; i++){
        ruisekiB[i] += ruisekiB[i-1];
    }

    ll ans = 0;

    for (ll i = 1; i <= N; i++){
        auto itr = lower_bound(vall(B), A[i]);
        ll tempans = 0;
        tempans += ruisekiB.back()-ruisekiB[distance(B.begin(), itr)-1] - distance(itr, B.end())*A[i];
        tempans += (distance(B.begin(), itr)-1)*A[i] - ruisekiB[distance(B.begin(), itr)-1];
        ans += tempans;
        ans %= 998244353;
    }
    cout << ans << "\n";
}

提出情報

提出日時
問題 D - Sum of Differences
ユーザ a1073741824
言語 C++23 (GCC 15.2.0)
得点 400
コード長 2664 Byte
結果 AC
実行時間 75 ms
メモリ 10396 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 32
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt
All 00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 1 ms 3588 KiB
00-sample-02.txt AC 1 ms 3636 KiB
01-01.txt AC 2 ms 3712 KiB
01-02.txt AC 2 ms 3608 KiB
01-03.txt AC 2 ms 3900 KiB
01-04.txt AC 2 ms 3708 KiB
01-05.txt AC 2 ms 3672 KiB
01-06.txt AC 2 ms 3900 KiB
01-07.txt AC 2 ms 3892 KiB
01-08.txt AC 2 ms 3688 KiB
01-09.txt AC 2 ms 3808 KiB
01-10.txt AC 2 ms 3708 KiB
01-11.txt AC 2 ms 3716 KiB
01-12.txt AC 2 ms 3580 KiB
01-13.txt AC 2 ms 3848 KiB
01-14.txt AC 2 ms 3664 KiB
01-15.txt AC 1 ms 3552 KiB
01-16.txt AC 1 ms 3452 KiB
01-17.txt AC 56 ms 9056 KiB
01-18.txt AC 59 ms 8256 KiB
01-19.txt AC 33 ms 8024 KiB
01-20.txt AC 32 ms 5788 KiB
01-21.txt AC 75 ms 10196 KiB
01-22.txt AC 43 ms 10396 KiB
01-23.txt AC 42 ms 10296 KiB
01-24.txt AC 63 ms 10256 KiB
01-25.txt AC 60 ms 10196 KiB
01-26.txt AC 32 ms 10272 KiB
01-27.txt AC 48 ms 8036 KiB
01-28.txt AC 51 ms 8684 KiB
01-29.txt AC 32 ms 8404 KiB
01-30.txt AC 56 ms 9272 KiB