結果

問題 No.1726 [Cherry 3rd Tune B] ジャマイカビアポン
ユーザー 👑 tatyam
提出日時 2021-10-19 08:10:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,946 bytes
コンパイル時間 3,624 ms
コンパイル使用メモリ 265,536 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-07 09:17:26
合計ジャッジ時間 10,061 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
using u32 = uint32_t;
using u64 = uint64_t;
void chmax(int& a, int b){ if(a < b) a = b; }

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int& p : P) cin >> p;
    int ans = 0;
    vector<pair<u32, u32>> A(N), B(M);
    for(auto& [a, b] : A){
        cin >> a >> b;
        a ^= 1u << 31;
        b ^= 1u << 31;
    }
    for(auto& [c, d] : B){
        cin >> c >> d;
        c ^= 1u << 31;
        d ^= 1u << 31;
    }
    auto comp = [](pair<u32, u32> a, pair<u32, u32> b){ return *reinterpret_cast<u64*>(&a) < *reinterpret_cast<u64*>(&b); };
    auto equal = [](pair<u32, u32> a, pair<u32, u32> b){ return *reinterpret_cast<u64*>(&a) == *reinterpret_cast<u64*>(&b); };
    vector<pair<pair<u32, u32>, int>> sortA(N);
    for(int i = 0; i < N; i++) sortA[i] = {A[i], P[i]};
    sort(sortA.begin(), sortA.end(), [&](auto& a, auto& b){ return comp(a.first, b.first); });
    for(int i = 0; i < 2; i++){
        for(auto& [c, d] : B) c = -c;
        for(int i = 0; i < 2; i++){
            for(auto& [c, d] : B) d = -d;
            sort(B.begin(), B.end(), comp);
            // 移動量を固定
            for(auto [a, b] : A) for(auto [c, d] : B){
                const int dx = a - c, dy = b - d;
                auto sortB = B;
                for(auto& [c, d] : sortB){
                    c += dx;
                    d += dy;
                }
                // ソートされていれば重なりが O(N + M)
                int score = 0, at = 0;
                for(auto [x, p] : sortA){
                    while(at < M && comp(sortB[at], x)) at++;
                    if(at == M) break;
                    if(equal(sortB[at], x)){
                        score += p;
                        at++;
                    }
                }
                chmax(ans, score);
            }
        }
    }
    cout << ans << endl;
}
0