제출 #442275

#제출 시각아이디문제언어결과실행 시간메모리
442275amunduzbaevAliens (IOI16_aliens)C++14
25 / 100
2077 ms17380 KiB
/* made by amunduzbaev */ #include "aliens.h" //~ #include "grader.cpp" #include "bits/stdc++.h" using namespace std; //~ #include <ext/pb_ds/assoc_container.hpp> //~ #include <ext/pb_ds/tree_policy.hpp> //~ using namespace __gnu_pbds; //~ template<class T> using oset = tree<T, //~ null_type, less_equal<T>, rb_tree_tag, //~ tree_order_statistics_node_update>; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vv vector #define mem(arr, v) memset(arr, v, sizeof arr) #define int long long #define degub(x) cout<<#x<<" : "<<x<<"\n" #define GG cout<<"here"<<endl; //~ void usaco(string s) { freopen((s+".in").c_str(),"r",stdin); //~ freopen((s+".out").c_str(),"w",stdout); NeedForSpeed } typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vii; typedef vector<pii> vpii; template<class T> bool umin(T& a, const T& b) { return a > b ? a = b, true : false; } template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, true : false; } template<int sz> using tut = array<int, sz>; //~ for P. Pankov problems //~ const int mod = 2021; //~ const int mod = (119 << 23)+1; const int N = 5e3+5; const int mod = 1e9+7; const ll inf = 1e18; const ld Pi = acos(-1); const int MX = 1e6+5; #define MULTI 0 int n, m, k, t, q, ans, res, a[N]; int x[N], y[N]; bool cmp(tut<3> a, tut<3> b){ if(a[1] != b[1]) return (a[1] > b[1]); return (a[0] < b[0]); } int dp[N][N]; vpii pp; int sq(int a) { return a * a; } //~ void dnc(int l, int r, int lx, int rx){ //~ if(l > r) return; //~ int m = (l + r)>>1, op = min(rx, m); //~ dp[m][k] = inf; //~ for(int i=min(rx, m);i>=lx;i--){ //~ int in = 0; //~ if(pp[i-1].ss >= pp[i].ff) in = sq(pp[i-1].ss - pp[i].ff + 1); //~ if(umin(dp[m][k], dp[i-1][k-1] + sq(pp[m].ss - pp[i].ff + 1) - in)) op = i; //~ } //~ dnc(l, m-1, lx, op); //~ dnc(m+1, r, op, rx); //~ } #define i32 int32_t int take_photos(i32 N, i32 M, i32 K, std::vector<i32> r, std::vector<i32> c){ n = N, m = M, k = K; for(int i=1;i<=n;i++){ x[i] = r[i-1], y[i] = c[i-1]; if(x[i] > y[i]) swap(x[i], y[i]); } vpii tt; for(int i=1;i<=n;i++) tt.pb({x[i], y[i]}); sort(all(tt), [&](pii a, pii b) { if(a.ff != b.ff) return a.ff < b.ff; return a.ss > b.ss; }); pp.pb(mp(-1, -1)); for(auto x : tt) if(x.ss > pp.back().ss) pp.pb(x); //~ for(auto x : pp) cout<<x.ff<<" "<<x.ss<<"\n"; n = sz(pp) - 1; for(int i=1;i<=n;i++) dp[i][0] = inf; for(k=1;k<=K;k++){ for(int i=1;i<=n;i++){ dp[i][k] = inf; for(int j=0;j<i;j++){ umin(dp[i][k], dp[j][k-1] + sq(pp[i].ss - pp[j+1].ff + 1) - sq(max(0ll, pp[j].ss - pp[j+1].ff + 1))); } } //~ for(int i=1;i<=n;i++) cout<<dp[i][k]<<" "; //~ cout<<"\n"; } res = inf; for(int i=1;i<=K;i++) umin(res, dp[n][i]); return res; } /* 2 6 2 1 4 4 1 4 7 2 0 3 4 6 4 3 4 5 */ //~ signed main(){ //~ NeedForSpeed //~ i32 n, m, k; cin>>n>>m>>k; //~ vv<i32> r, c; //~ for(int i=0;i<n;i++){ //~ int x, y; cin>>x>>y; //~ r.pb(x), c.pb(y); //~ } //~ cout<<take_photos(n, m, k, r, c)<<"\n"; //~ return 0; //~ }
#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...