Submission #1248225

#TimeUsernameProblemLanguageResultExecution timeMemory
1248225Zbyszek99Garden (JOI23_garden)C++20
0 / 100
96 ms33176 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define ull unsigned long long #define ff first #define ss second #define pii pair<int,int> #define pll pair<long long, long long> #define vi vector<int> #define vl vector<long long> #define pb push_back #define rep(i, b) for(int i = 0; i < (b); ++i) #define rep2(i,a,b) for(int i = a; i <= (b); ++i) #define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c) #define count_bits(x) __builtin_popcountll((x)) #define all(x) (x).begin(),(x).end() #define siz(x) (int)(x).size() #define forall(it,x) for(auto& it:(x)) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; //mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());} //ll los(ll a, ll b) {return a + (mt() % (b-a+1));} const int INF = 1e9+50; const ll INF_L = 1e18+40; const ll MOD = 1e9+7; int prev_[500001]; int nxt_[500001]; int when_del[5001]; int t1_list[5001]; vl t2_list[5001]; vi del_list[10006]; int n,m,d; int max_gap; int cur_max_h = 0; void del(int x) { max_gap = max(max_gap,(nxt_[x] - prev_[x]-1 + d) % d); nxt_[prev_[x]] = nxt_[x]; prev_[nxt_[x]] = prev_[x]; } int solve(int beg) { rep2(i,beg,d*2-1) del_list[i] = {}; rep(i,d) del_list[when_del[i]].pb(i); rep(i,d) { nxt_[i] = (i+1)%d; prev_[i] = (i-1+d)%d; } rep(i,d) if(when_del[i] == 0 && beg > 0) del(i); max_gap = 0; int ans = 1e9; rep2(end_,beg,d*2-1) { forall(it,del_list[end_]) del(it); if(end_ >= cur_max_h) ans = min(ans,(end_-beg+1) * (d-max_gap)); } return ans; } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //random_start(); cin >> n >> m >> d; vector<pll> t1; vector<pll> t2; rep(i,n) { int a,b; cin >> a >> b; t1.pb({a,b}); when_del[a] = 10005; cur_max_h = max(cur_max_h,b); t1_list[b]++; } rep(i,m) { ll a,b; cin >> a >> b; t2.pb({a,b}); when_del[a] = b+1; t2_list[b].pb(a); } int ans = 1e9; rep(l,d) { ans = min(ans,solve(l)); if(t1_list[l] != 0) cur_max_h = max(cur_max_h,l+d); forall(it,t2_list[l]) { when_del[it] = max(when_del[it],l+d); } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...