Submission #1297747

#TimeUsernameProblemLanguageResultExecution timeMemory
1297747hiepsimauhongAliens (IOI16_aliens)C++20
0 / 100
2 ms2364 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; //#define int long long using Maxint = long long; #define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I) #define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I) #define FOA(I, A) for(auto &I : A) #define print(A,L,R) FOR(OK, L, R){if(abs(A[OK]) >= oo / 10)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n'; #define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n'; #define printz(A,L,R) FOR(OK, 0, L){FOR(KO, 0, R){if(abs(A[OK][KO]) <= oo / 10)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n'; #define fs first #define sd second #define ii pair<int,int> #define iii pair<int, ii> #define all(A) A.begin(), A.end() #define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define FILE "BUFF" const int N = 500 + 5; const int mod = 1e9 + 7; const Maxint oo = 1e18; int n, m, k; ii a[N], rl[N]; int add[N], cost[N], f[N]; Maxint dp[N][N]; /*void init(){ cin >> n >> m >> k; FOR(i, 1, n){ cin >> a[i].fs; } FOR(i, 1, n){ cin >> a[i].sd; if(a[i].fs > a[i].sd) swap(a[i].fs, a[i].sd); } }*/ void PreWork(){ sort(a + 1, a + 1 + n, [&](ii &u, ii &v){ if(u.sd == v.sd){ return u.fs > v.fs; } return u.sd < v.sd; }); stack<int> st; FOR(i, 1, n){ while(!st.empty() && a[st.top()].fs >= a[i].fs){ add[i] += add[st.top()]; st.pop(); } add[i]++; st.push(i); } n = 0; while(!st.empty()){ rl[++n] = a[st.top()]; f[n] = add[st.top()]; st.pop(); } reverse(rl + 1, rl + 1 + n); reverse(f + 1, f + 1 + n); FOR(i, 2, n){ int x = rl[i].fs; int y = rl[i - 1].sd; if(x <= y){ cost[i] = (y - x + 1) * (y - x + 1); } } } Maxint Caculate(){ memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; FOR(h, 1, n){ FOR(i, 1, n){ FOR(j, 1, i){ Maxint u = rl[j].fs; Maxint v = rl[i].sd; dp[h][i] = min(dp[h][i], dp[h - 1][j - 1] - cost[j] + (v - u + 1) * (v - u + 1)); } } } Maxint ans = oo; FOR(i, 1, k){ ans = max(ans, dp[i][n]); } return ans; } Maxint take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c){ n = _n; m = _m; k = _k; FOR(i, 1, n){ a[i].fs = r[i - 1]; a[i].sd = c[i - 1]; } PreWork(); return Caculate(); } /*signed main(){ quickly if(fopen(FILE".inp", "r")){ freopen(FILE".inp", "r", stdin); freopen(FILE".out", "w", stdout); } init(); PreWork(); cout << Caculate(); }*/

Compilation message (stderr)

aliens.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...