結果
| 問題 | 
                            No.1726 [Cherry 3rd Tune B] ジャマイカビアポン
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  tatyam
                         | 
                    
| 提出日時 | 2021-10-19 08:12:37 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,061 bytes | 
| コンパイル時間 | 4,697 ms | 
| コンパイル使用メモリ | 287,116 KB | 
| 実行使用メモリ | 13,640 KB | 
| 最終ジャッジ日時 | 2024-10-07 09:18:12 | 
| 合計ジャッジ時間 | 12,511 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 14 TLE * 2 -- * 23 | 
ソースコード
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#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;
}
            
            
            
        
            
tatyam