結果
問題 | No.1767 BLUE to RED |
ユーザー |
👑 ![]() |
提出日時 | 2021-11-26 23:28:48 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 2,715 ms |
コンパイル使用メモリ | 109,024 KB |
最終ジャッジ日時 | 2025-01-26 01:54:11 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N,M; cin >> N >> M; vector<i64> A(N); rep(i,N) cin >> A[i]; vector<vector<i64>> B(A.size() + 1); rep(i,M){ int b; cin >> b; int p = upper_bound(A.begin(), A.end(), b) - A.begin(); B[p].push_back(b); } vector<i64> ans(B.size(), 0); rep(i,B.size()) if(!B[i].empty()) ans[i] = 1001001001; for(int i=0; i<A.size(); i++) if(!B[i].empty()) ans[i] = min(ans[i], A[i] - B[i].front()); for(int i=0; i<A.size(); i++) if(!B[i+1].empty()) ans[i+1] = min(ans[i+1], B[i+1].back() - A[i]); for(int i=1; i<A.size(); i++) if(!B[i].empty()){ i64 d = A[i] - A[i-1] - 1; for(int j=0; j+1 < B[i].size(); j++){ ans[i] = min(ans[i], d - (B[i][j+1] - B[i][j] - 1)); } } i64 finalans = 0; for(auto a : ans) finalans += a; cout << finalans << endl; return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;