Submission #702192

#TimeUsernameProblemLanguageResultExecution timeMemory
702192nicky4321Group Photo (JOI21_ho_t3)C++14
44 / 100
5035 ms5212 KiB
//#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include<bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second #define PB push_back #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> #define ALL(x) x.begin(), x.end() #define SZ(x) (int)x.size() #define vi vector<int> #define vl vector<ll> #define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++) #define IOS ios_base::sync_with_stdio(false); cin.tie(0); using namespace std; const int MAX = 5007, MOD = 1e9 + 7; ll a[MAX], bit[MAX], dp[MAX][MAX], ans[MAX]; void upd(int x, int v){ while(x < MAX){ bit[x] += v; x += x & -x; } } int qry(int x){ int res = 0; while(x){ res += bit[x]; x -= x & -x; } return res; } void solve(){ int n; cin >> n; for(int i = 1;i <= n;i++){ cin >> a[i]; ans[i] = 2e18; } for(int i = 1;i <= n;i++){ for(int j = 1;j <= i;j++){ for(int k = n;k >= 1;k--){ if(i < a[k]){ dp[j][i] += qry(n); upd(n + 1, 1); }else if(j <= a[k] && a[k] <= i){ int pos = i - a[k] + j + 1; dp[j][i] += qry(pos - 1); upd(pos, 1); } } for(int k = 1;k <= n;k++){ if(i < a[k]) upd(n + 1, -1); else if(j <= a[k] && a[k] <= i){ int pos = i - a[k] + j + 1; upd(pos, -1); } } } } for(int i = 0;i < n;i++){ for(int j = 1;j <= n;j++) ans[j] = min(ans[j], ans[i] + dp[i + 1][j]); } cout << ans[n] << '\n'; } int main(){ IOS // CASE solve(); 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...